C# Program to Demonstrate the Gettype() Method of Enum Class

You are currently viewing C# Program to Demonstrate the Gettype() Method of Enum Class

C# program to demonstrate the GetType() method of Enum class

using System;

class Sample
{
    enum Colors { RED=0,GREEN=1,YELLOW=3,WHITE=4,BLACK=5};
    enum Directions { EAST,WEST,NORTH,SOUTH};

    //Entry point of Program
    static public void Main()
    {
        string type = "";

        Colors      color       = Colors.RED;
        Directions  direction   = Directions.NORTH;

        type = color.GetType().ToString();
        Console.WriteLine(type);

        type = direction.GetType().ToString();
        Console.WriteLine(type);

    }
}
Sample+Colors
Sample+Directions
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