Single.GetTypeCode Method in C# with Examples


The Single.GetTypeCode() method in C# is used to return the TypeCode for value type Single.

Syntax

The syntax is as follows −

public TypeCode GetTypeCode ();

Example

Let us now see an example −

 Live Demo

using System;
public class Demo {
   public static void Main() {
      float f1 = 15.3f;
      float f2 = 35.9f;
      Console.WriteLine("Value1 = "+f1);
      Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode());
      Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode());
      Console.WriteLine("\nValue2 = "+f2);
      Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode());
      Console.WriteLine("TypeCode for Value1 = "+f2.GetTypeCode());
      Console.WriteLine("\nIs f1 and f2 equal? = "+f1.CompareTo(f2));
   }
}

Output

This will produce the following output −

Value1 = 15.3
Hashcode for Value1 = 1098173645
TypeCode for Value1 = Single
Value2 = 35.9
Hashcode for Value2 = 1108318618
TypeCode for Value1 = Single

Is f1 and f2 equal? = -1

Example

Let us now see another example −

 Live Demo

using System;
public class Demo {
   public static void Main() {
      float f1 = 19.3f;
      float f2 = Single.MaxValue;
      Console.WriteLine("Value1 = "+f1);
      Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode());
      Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode());
      Console.WriteLine("\nValue2 = "+f2);
      Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode());
      Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode());
   }
}

Output

This will produce the following output −

Value1 = 19.3
Hashcode for Value1 = 1100637798
TypeCode for Value1 = Single
Value2 = 3.402823E+38
Hashcode for Value2 = 2139095039
TypeCode for Value2 = Single
raja
Published on 04-Dec-2019 11:19:19
Advertisements