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?
The accepted solution returns an Enum object. To return the value you want this solution:
dim MyGender as string = "Male"
dim Value as integer
Value = DirectCast([Enum].Parse(GetType(Gender), MyGender), Integer)
Can also do it this way:
value = cInt([enum].Parse(GetType(Gender), MyGender))