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 . . .
Table of Contents