C#のSingle.ToStringメソッド
C#のSingle.ToString()メソッドは、このインスタンスの数値を同等の文字列表現に変換するために使用されます。
構文
構文は次のとおりです-
public override string ToString ();
例
例を見てみましょう-
using System; public class Demo { public static void Main(){ float f1 = 10.0f/0.0f; float f2 = -3.0f; Console.WriteLine("Value1 (String representation) = "+f1.ToString()); 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("\nValue1 (String representation) = "+f2.ToString()); 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 (String representation) = ∞ 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 Value1 (String representation) = -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
例
別の例を見てみましょう-
using System; public class Demo { public static void Main(){ float f1 = 5.0f/0.0f; float f2 = 0.0f/0.0f; Console.WriteLine("Value1 (String representation) = "+f1.ToString()); 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 negative infinity? = "+Single.IsNegativeInfinity(f1)); Console.WriteLine("\nValue2 (String representation) = "+f2.ToString()); 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 negative infinity? = "+Single.IsNegativeInfinity(f2)); } }
出力
これにより、次の出力が生成されます-
Value1 (String representation) = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Is Value1 a negative infinity? = False Value2 (String representation) = NaN Hashcode for Value2 = -4194304 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = True Is Value2 a negative infinity? = False
-
JavaScript RegExp toString()メソッド
RegExp toString()メソッドは、正規表現の文字列値を返すために使用されます。 以下は、RegExp toString()メソッドのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title&
-
C#列挙型ToString()メソッド
ToString()メソッドは、このインスタンスの値を同等の文字列表現に変換します。 まず、列挙型を設定します。 enum Vehicle { Car, Bus, Truck, Motobike }; 同等の文字列表現に変換するには、ToString()を使用します。 Vehicle.Car.ToString("d") 例 using System; public class Demo { enum Vehicle { Car, Bus, Truck, Motobike }; public static void Ma