Udostępnij za pośrednictwem


How to: Determine the String Associated with an Enumeration Value (Visual Basic)

The GetValues and GetNames methods allow you to determine the strings and values associated with enumeration members.

To determine the string associated with an enumeration

  • Use the GetNames method to retrieve the strings associated with the enumeration members. This example declares an enumeration, flavorEnum, then uses the GetNames method to display the strings associated with each member.

    Public Enum flavorEnum
      salty
      sweet
      sour
      bitter
    End Enum
    
    Private Sub TestMethod()
      MsgBox("The strings in the flavorEnum are:")
      Dim i As String
      For Each i In [Enum].GetNames(GetType(flavorEnum))
          MsgBox(i)
      Next
    End Sub
    

See Also

Tasks

How to: Declare Enumerations (Visual Basic)

How to: Refer to an Enumeration Member (Visual Basic)

How to: Iterate Through An Enumeration in Visual Basic

Reference

Enum Statement (Visual Basic)

GetValues

GetNames

Enum

Concepts

Enumerations and Name Qualification (Visual Basic)

When to Use an Enumeration (Visual Basic)