HOWTO? Iterate all legal values of an ENUM

  • Thread starter Thread starter Lee Gillie
  • Start date Start date
L

Lee Gillie

I see this was posted a long time ago, but it has since expired.

Given....

Public Enum Fruit
Apple
Banana
Cherry
Peach
Strawberry
Tomatoe
End Enum

I'd like to be do something of this flavor in VB.NET....

Dim frMyFruit as Fruit

For Each frMyFruit in Fruit
...
Next

Of course it complains that "Fruit" is a type in the FOR EACH.
Does the language or runtime provide SOME WAY to find all legal values?

TIA for your learned advice.
Best regards,
Lee Gillie, Spokane
 
Never mind, I think I see it...

Dim frMyFruit as Fruit

For Each frMyFruit In [Enum].GetValues(GetType(Fruit))
...
Next

- Lee
 
Lee Gillie said:
Given....

Public Enum Fruit
Apple
Banana
Cherry
Peach
Strawberry
Tomatoe
End Enum

I'd like to be do something of this flavor in VB.NET....

Dim frMyFruit as Fruit

For Each frMyFruit in Fruit
...
Next

Of course it complains that "Fruit" is a type in the FOR EACH.
Does the language or runtime provide SOME WAY to find all legal values?

\\\
For Each f As Fruit In [Enum].GetValues(GetType(Fruit))
...
Next f
///
 
Back
Top