Enumerating an enum

  • Thread starter Thread starter pdavis68
  • Start date Start date
P

pdavis68

How can I iterate through all the values of an enum? I'm looking through all
the information of the type in the watch window to see if there's some way
to get at the values through reflection, but I don't see it. Anyone know?
Thanks.

Pete
 
How can I iterate through all the values of an enum? I'm looking through all
the information of the type in the watch window to see if there's some way
to get at the values through reflection, but I don't see it. Anyone know?

Enum.GetValues(typeof(MyEnum));
 
Enum.GetValues()

Or, through reflection (for fun):

foreach (FieldInfo fi in typeof(SomeEnum).GetFields())
{
MyEnum value = (MyEnum)fi.GetValue(new MyEnum());
...
}
 
Back
Top