How to find count of number if items in an enumeration?

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Is is possible to find a count of the number of items in an enumeration?
Something like:


Public Enum MyEnum
First = 1
Second = 2
Third = 3
End Enum

EnumCount(MyEnum) = 3


Is it also possible to iterate through an enumeration? Something akin to
this (which doesn't work):

Dim int as Integer
For Each int in MyEnum
...
Next int


- Don
 
Don said:
Is is possible to find a count of the number of items in an enumeration?
Something like:

Is it also possible to iterate through an enumeration? Something akin to
this (which doesn't work):

Check out the GetNames method of the Enum class. Once you get the
array of names, you can use it's Length property to tell you how many
there are....

LFS
 
Don said:
Is is possible to find a count of the number of items in an enumeration?
Something like:


Public Enum MyEnum
First = 1
Second = 2
Third = 3
End Enum

EnumCount(MyEnum) = 3

\\\
Dim n As Integer = [Enum].GetValues(GetType(MyEnum)).Lenght
///
Is it also possible to iterate through an enumeration? Something akin to
this (which doesn't work):

Dim int as Integer
For Each int in MyEnum
...
Next int

Take a look at '[Enum].GetValues' and '[Enum].GetNames'.
 
Back
Top