C# | Type.GetTypeCode() Method
Type.GetTypeCode() Method is used to get the underlying type code of the specified Type.
Syntax: public static TypeCode GetTypeCode (Type type);
Here, it takes the type whose underlying type code to get.
Return Value: This method returns the code of the underlying type, or Empty if type is null.
Below programs illustrate the use of Type.GetTypeCode() Method:
Example 1:
using System;
using System.Globalization;
using System.Reflection;
class GFG {
public static void Main()
{
Type type = typeof ( int );
TypeCode code = Type.GetTypeCode(type);
Console.WriteLine( "TypeCode is {0}" , code);
}
}
|
Output:
TypeCode is Int32
Example 2:
using System;
using System.Globalization;
using System.Reflection;
class GFG {
public static void Main()
{
get ( typeof ( int ));
get ( typeof ( decimal ));
get ( typeof ( double ));
get ( typeof ( short ));
get ( typeof ( string ));
}
public static void get (Type type)
{
TypeCode code = Type.GetTypeCode(type);
Console.WriteLine( "TypeCode of {1} is {0}" , code, type);
}
}
|
Output:
TypeCode of System.Int32 is Int32
TypeCode of System.Decimal is Decimal
TypeCode of System.Double is Double
TypeCode of System.Int16 is Int16
TypeCode of System.String is String
Reference:
Last Updated :
20 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...