you can add Description tags to your enum like below
public enum State
{
[Description("Karnataka")]
KARNATAKA = 1,
[Description("Gujarat")]
GUJRAT = 2,
[Description("Assam")]
ASSAM = 3,
[Description("Maharashtra")]
MAHARASHTRA = 4,
[Description("Goa")]
GOA = 5
}
And then get assigned Desription string from enum like below
State stateVal = State.GOA;
string stateName = GetEnumDescription(stateVal);
if you have state as in number as you have mentioned comments, you can still easily cast it to enum type.
int stateVal = 2;
string stateName = GetEnumDescription((State)stateVal);
GetEnumDescription()
which returns string for name of Enumerations.
public static string GetEnumDescription(Enum enumVal)
{
System.Reflection.MemberInfo[] memInfo = enumVal.GetType().GetMember(enumVal.ToString());
DescriptionAttribute attribute = CustomAttributeExtensions.GetCustomAttribute<DescriptionAttribute>(memInfo[0]);
return attribute.Description;
}
NOTE
As operation on enum is less costly than string operations, string value of enum should be limited to display purpose only, while internally you must use enum itself in logic.
The way to get string value of enum is more preferred. As if you have used enum at lot of places in your code, and you need to change text on display, you will have to change text at one place only.
For example,
Suppose you have used this enum throughout your project and then you realize that your spelling of Gujarat is wrong, if you change the text of enum it self you need to change it through whole code (thankfully visual studio makes it little easier) while if you use Description as label to be display you will only need to change that only.
Or
when you Space in name (which you have to display).
EG. "Jammu and Kashmir" is another state of India.
you can have abbreviation (here "JK") in enum name and complete string with space in description.