-2

I have an enumeration as follows:

public enum MyEnumeration
{
  myFirstValue = 0,
  mySecondValue = 1
}

Question, I want the Type of my enumeration as a string eg:

var str = MyEnumeration.ToString();
/// str = "MyEnumeration"

(FYI, the above doesn't work)

I can find plenty of answers online to get the string values of 'myFirstValue' and 'mySecondValue', but not the Enumeration.

Thanks for your help!

(ninja edit) Thanks to everyone for taking the time to answer. I don't believe this is a duplicate of the marked question. This is a direct question against an Enumeration, the solution to this is not provided in the duplicate question

Mr Giggles
  • 2,483
  • 3
  • 22
  • 35

1 Answers1

5

If you want the type name of your enum, use:

typeof(MyEnumeration).Name

or in C# 6

nameof(MyEnumeration)
René Vogt
  • 43,056
  • 14
  • 77
  • 99