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
  • 46,787
  • 42
  • 99
  • 147

3 Answers3

15

Enum.GetValues

Oliver Hanappi
  • 11,682
  • 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
  • 94,937
  • 19
  • 203
  • 272
7

Enum.GetValues(typeof(SomeEnum));

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

bastijn
  • 5,681
  • 4
  • 26
  • 42