例を使用したC#のSingle.IsPositiveInfinity()メソッド
C#のSingle.IsPositiveInfinity()メソッドは、指定された数値が正の無限大と評価されるかどうかを示す値を返すために使用されます。
構文
構文は次のとおりです-
public static bool IsPositiveInfinity (float val);
上記のパラメータvalは、単精度浮動小数点数です。
例
例を見てみましょう-
using System; public class Demo { public static void Main() { float f1 = -25.0f/0.0f; float f2 = 5.0f/0.0f; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("Is Value1 a positive infinity? = "+Single.IsPositiveInfinity(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); Console.WriteLine("Is Value2 a positive infinity? = "+Single.IsPositiveInfinity(f2)); } }
出力
これにより、次の出力が生成されます-
Value1 = -∞ Hashcode for Value1 = -8388608 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Is Value1 a positive infinity? = False Value2 = ∞ Hashcode for Value2 = 2139095040 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = True Is Value2 NaN? = False Is Value2 a positive infinity? = True
例
別の例を見てみましょう-
using System; public class Demo { public static void Main() { float f1 = 10.0f/0.0f; float f2 = -3.0f; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("Is Value1 a positive infinity? = "+Single.IsPositiveInfinity(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); Console.WriteLine("Is Value2 a positive infinity? = "+Single.IsPositiveInfinity(f2)); } }
出力
これにより、次の出力が生成されます-
Value1 = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Is Value1 a positive infinity? = True Value2 = -3 Hashcode for Value2 = -1069547520 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = False Is Value2 a positive infinity? = False
-
例を使用したC#のInt32.GetHashCodeメソッド
C#のInt32.GetHashCode()メソッドは、現在のインスタンスのハッシュコードを返すために使用されます。 構文 以下は構文です- public override int GetHashCode (); 例 Int32.GetHashCode()メソッドを実装する例を見てみましょう- using System; public class Demo { public static void Main(){ int val1 = Int32.MinValue; int val
-
例を使用したC#のInt16.GetHashCode()メソッド
C#のInt16.GetHashCode()メソッドは、現在のインスタンスのハッシュコードを返すために使用されます。 構文 以下は構文です- public override int GetHashCode (); 例 Int16.GetHashCode()メソッドを実装する例を見てみましょう- using System; public class Demo { public static void Main(){ short val1 = 20; short val2 = 25;