Int32.GetTypeCode Method in C# with Examples


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

Syntax

Following is the syntax −

public TypeCode GetTypeCode ();

Example

Let us now see an example to implement the Int32.GetTypeCode() method −

using System;
public class Demo {
   public static void Main(){
      int val1 = 100;
      int val2 = 50;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+val1.Equals(val2));
      Console.WriteLine("HashCode for Value1 = "+val1.GetHashCode());
      Console.WriteLine("HashCode for Value2 = "+val2.GetHashCode());
      TypeCode type1 = val1.GetTypeCode();
      TypeCode type2 = val2.GetTypeCode();
      Console.WriteLine("TypeCode for Value1 = "+type1);
      Console.WriteLine("TypeCode for Value2 = "+type2);
   }
}

Output

This will produce the following output −

Value1 = 100
Value2 = 50
Are they equal? = False
HashCode for Value1 = 100
HashCode for Value2 = 50
TypeCode for Value1 = Int32
TypeCode for Value2 = Int32

Example

Let us now see another example to implement the Int32.GetTypeCode() method −

using System;
public class Demo {
   public static void Main(){
      int val1 = 5;
      int val2 = Int32.MaxValue;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      TypeCode type1 = val1.GetTypeCode();
      TypeCode type2 = val2.GetTypeCode();
      Console.WriteLine("TypeCode for Value1 = "+type1);
      Console.WriteLine("TypeCode for Value2 = "+type2);
   }
}

Output

This will produce the following output −

Value1 = 5
Value2 = 2147483647
TypeCode for Value1 = Int32
TypeCode for Value2 = Int32

Updated on: 07-Nov-2019

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements