C# program to print the name of enum constant based on an integer value

Sometimes we get frustrated if we do not get the information we need in some articles. But this article has all the information you need when you read C# program to print the name of enum constant based on an integer value. Read patiently and understand.

C# program to print the name of enum constant based on an integer value

C# program to print the name of enum constant based on an integer value

//C# program to print the name of enum based on an integer value.

using System;

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

class EnumDemo
{
   
    static void Main(string[] args)
    {
        Console.WriteLine("Name is: {0}", Enum.GetName(typeof(COLOR), 2));
        Console.WriteLine("Name is: {0}", Enum.GetName(typeof(COLOR), 5)); 
    }
}
Name is: YELLOW
Name is: BLUE
Press any key to continue . . .

Final Words

We hope the C# program to print the name of enum constant based on an integer value article helped you in some way. And let us know if you have any doubts. Thanks

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

Share on:

Leave a Comment