C# Program to Get the Type-Code of Enum Constants

You are currently viewing C# Program to Get the Type-Code of Enum Constants

C# program to get the type-code of enum constants

//C# program to get the type code of enum constants.

using System;

enum COLOR 
{
    RED,GREEN,YELLOW,BLACK,WHITE, BLUE
}

class EnumDemo
{
    static void PrintTypeCode(COLOR color)
    {
        switch (color)
        { 
            case COLOR.RED:
                Console.WriteLine("Color is Red,    typecode: " + COLOR.RED.GetTypeCode());
                break;
            case COLOR.GREEN:
                Console.WriteLine("Color is Green,  typecode: " + COLOR.GREEN.GetTypeCode());
                break;
            case COLOR.YELLOW:
                Console.WriteLine("Color is Yellow, typecode: " + COLOR.YELLOW.GetTypeCode());
                break;
            case COLOR.BLACK:
                Console.WriteLine("Color is Black,  typecode: " + COLOR.BLACK.GetTypeCode());
                break;
            case COLOR.WHITE:
                Console.WriteLine("Color is White,  typecode: " + COLOR.WHITE.GetTypeCode());
                break;
            case COLOR.BLUE:
                Console.WriteLine("Color is Blue,   typecode: " + COLOR.BLUE.GetTypeCode());
                break;
        }
    }
    static void Main(string[] args)
    {
        PrintTypeCode(COLOR.RED);
        PrintTypeCode(COLOR.GREEN);
        PrintTypeCode(COLOR.BLUE);
    }
}
Color is Red,    typecode: Int32
Color is Green,  typecode: Int32
Color is Blue,   typecode: Int32
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply