recurse through members of an enum

  • Thread starter Laszlo Szijarto
  • Start date
L

Laszlo Szijarto

What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo
 
W

William Stacey

Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
 
A

Alvin Bruney

I don't think this is possible since an enum is a type. You can iterate thru
collections which implement ienumerable, but an enum is not a collection.
 
M

Michael Bray

I don't think this is possible since an enum is a type. You can
iterate thru collections which implement ienumerable, but an enum is
not a collection.

You can do this type of operation with Reflection... see previous post
replies for some specific code that demonstrates it.

-mbray
 
A

Alvin Bruney

Thanks
Michael Bray said:
You can do this type of operation with Reflection... see previous post
replies for some specific code that demonstrates it.

-mbray
 
A

Alvin Bruney

sweet code william. sweet code
William Stacey said:
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
 

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

Similar Threads

about enum 3
Enum TypeConverter 3
number of values in enum 2
Number of members in an Enum 2
Interface and enum 3
enum type 3
Looping through multiple enumerations 1
Help with multi-dimensional arrays 1

Top