On 25 Nov 2003 07:30:10 -0800, giant food wrote:
[color=blue]
> This seems like a long shot, but I wondered if there's a way to loop
> over the values in an Enum. For example, say I have an Enum as
> follows:
>
> Public Enum statusValues
> Ready
> Running
> Finished
> Error
> End Enum
>
> '.....
>
> I'd like to be able to loop over and print out these values' names
> something like this:
>
> For Each item in statusValues
> Console.WriteLine(item.ToString)
> Next
>
> ...the reason being that, if I add elements to my Enum object, I won't
> have to go change the code that prints out their names. Thanks!
>
> --Frank[/color]
The Enum class has static methods that allow you to do this.
For example, to get the name of a specific enum value that was passed to
you, you could use
string name = Enum.GetName(typeof(MyEnumType),SomeEnumValue)
--
Roy Osherove
weblog:
http://www.iserializable.com