Getting Enum Value from Value in CSharp

Hello to everyone,

In this article, I will give information about getting Enum value from value in CSharp.

In CSharp, there may be a need to read Enum value in some cases.

You can do this easily using the code below.

using System;

namespace ConsoleAppOrnek
{
    class Program
    {
        public enum Days { 
            Monday = 1, 
            Tuesday = 2, 
            Wednesday = 3, 
            Thursday = 4, 
            Friday = 5, 
            Saturday = 6, 
            Sunday = 7
        }

        static void Main(string[] args)
        {
            int value = 5; 
            string day = Enum.GetName(typeof(Days), value); 
            Console.WriteLine(day);
        }
    }
}

When you run the above code, you will see a result similar to the one below.

Getting Enum Value from Value in CSharp

As you can see, the Enum value has been read.

Good luck to everyone and business and life

23 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

Share

Don`t copy text!