Home All Groups Group Topic Archive Search About

Get all members of an Enum

Author
15 Aug 2006 4:56 PM
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

Author
15 Aug 2006 5:23 PM
Tom Shelton
Samuel Shulman wrote:
> 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,

--
Tom Shelton [MVP]