Get all members of an Enum

  • Thread starter Thread starter Samuel Shulman
  • Start date Start date
S

Samuel Shulman

I can't remember what is the namespace/class that can be used to retrieve
all the members of an enum

Thank you,
Samuel
 
Samuel said:
I can't remember what is the namespace/class that can be used to retrieve
all the members of an enum

System.Enum

Option Explicit On
Option Strict On

Imports System

Module Module1
Private Enum TestEnum
one = 1
two
three
four
End Enum

Sub Main()
Dim names As String() = [Enum].GetNames(GetType(TestEnum))

For Each valueName As String In names
Console.WriteLine("{0} = {1}", valueName,
DirectCast([Enum].Parse(GetType(TestEnum), valueName), Integer))
Next
End Sub

End Module

HTH,
 
Back
Top