By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Enumerating an enum

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pd******@hotmail.com <pe**@petedavis.net> wrote:
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));

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
Enum.GetValues()

Or, through reflection (for fun):

foreach (FieldInfo fi in typeof(SomeEnum).GetFields())
{
MyEnum value = (MyEnum)fi.GetValue(new MyEnum());
...
}
"pd******@hotmail.com" <pe**@petedavis.net> wrote in message
news:42******************************@news.meganet news.com...
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.