Get enum name when value is known
In c# 6 you can use nameof
.
nameof(YourEnum.Something)
results in:
something
Another option is to use the GetName
static method:
Enum.GetName(typeof(MyEnumClass), n);
This has the benefit that the code speaks for itself. It should be obvious that it returns the name of the enum (which may be a bit difficult to realize when you use for example the ToString
method).
return ((MyEnumClass)n).ToString();