12

Possible Duplicate:
How do I enumerate an enum?

Say I have an enum type MyEnum. Is there a way in C# to get a list of all possible values for an enum of type MyEnum?

Community
  • 1
  • 1
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150

3 Answers3

15

Enum.GetValues

Oliver Hanappi
  • 12,046
  • 7
  • 51
  • 68
11

An instance of the enum can have any assignable to the underlying type (i.e., int.MinValue through int.MaxValue for any regular enum). You can get a list of the named values by calling Enum.GetNames and Enum.GetValues.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
7

Enum.GetValues(typeof(SomeEnum));

will return an array with all the values. I do not know if this helps you.

bastijn
  • 5,841
  • 5
  • 27
  • 43