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.
As you can see, the Enum value has been read.
Good luck to everyone and business and life
28 Views