Get enum name when value is known

Viewed 58925

I have an enum that has different colors in it. I would like to pass some function an int and have it return the color name that is in the enum in that position.

What's the way to do this?

7 Answers

((YourEnum)Value).ToString()

For eg.

((MyEnum)2).ToString()

Note: Points to remember, your enum should be decorated by [Flag] and enum value must be greater than 0.

Related