How to get the typecode for enum in C#?
Last Updated :
23 Jul, 2019
Enum.GetTypeCode Method is used to get the type code of the underlying type of this enumeration member.
Syntax:
public TypeCode GetTypeCode ();
Returns: This method returns type code of the underlying type of this instance.
Exception: This method will give InvalidOperationException if the enumeration type is unknown.
Example:
using System;
class GFG {
enum Color {Blue, Black };
public static void Main(String[] args)
{
Color c1 = Color.Blue;
Console.Write( "TypeCode of Enum Constant " + c1 + " : " );
Console.WriteLine(c1.GetTypeCode());
Color c2 = Color.Black;
Console.Write( "TypeCode of Enum Constant " + c2 + " : " );
Console.WriteLine(c2.GetTypeCode());
}
}
|
Output:
TypeCode of Enum Constant Blue : Int32
TypeCode of Enum Constant Black : Int32
Reference:
Share your thoughts in the comments
Please Login to comment...