C# Program to Print the Name of Enum Constant Based on an Integer Value

You are currently viewing 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 . . .

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