Vb.net – Parse a string to an Enum value in VB.NET

enumsvb.net

How can I parse a string in VB.NET to enum value?

Example I have this enum:

Public Enum Gender
    NotDefined
    Male
    Female
End Enum

how can I convert a string "Male" to the Gender enum's Male value?

Best Solution

Dim val = DirectCast([Enum].Parse(GetType(Gender), "Male"), Gender)