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());
...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top