Iterate Through Enum

Assume you have a list of Enum items:

Public Class AccessRight

   Public Enum Roles

      GeneralMember = 0

      Client = 1

      ...

   End Enum

End Class

Then you can iterate this list of name and value pair by using:

Dim arr As Array = System.Enum.GetValues(GetType(AccessRight.Roles))

 

For i As Integer = arr.GetLowerBound(0) To arr.GetUpperBound(0)

   'Name

   'System.Enum.GetName(GetType(AccessRight.Roles), arr.GetValue(i))

 

   'Value

   'CInt(arr.GetValue(i)))

Next

No Comments