Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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.


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.


// C# program to illustrate the
// Enum.GetTypeCode() Method
using System;
class GFG {
    enum Color {Blue, Black };
    // Main Method
    public static void Main(String[] args)
        Color c1 = Color.Blue;
        Console.Write("TypeCode of Enum Constant " + c1 + " : ");
        // Using the GetTypeCode() Method
        Color c2 = Color.Black;
        Console.Write("TypeCode of Enum Constant " + c2 + " : ");
        // Using the GetTypeCode Method
TypeCode of Enum Constant Blue : Int32
TypeCode of Enum Constant Black : Int32


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!