Enum String Name from Value
Use this:
string bob = nameof(EnumDisplayStatus.Visible);
If you need to get a string "Visible"
without getting EnumDisplayStatus
instance you can do this:
int dbValue = GetDBValue();
string stringValue = Enum.GetName(typeof(EnumDisplayStatus), dbValue);
You can convert the int
back to an enumeration member with a simple cast, and then call ToString()
:
int value = GetValueFromDb();
var enumDisplayStatus = (EnumDisplayStatus)value;
string stringValue = enumDisplayStatus.ToString();
Try this:
string m = Enum.GetName(typeof(MyEnumClass), value);