recurse through members of an enum

  • Thread starter Thread starter Laszlo Szijarto
  • Start date 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
 
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
 
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.
 
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
 
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
 
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);
 
Back
Top