Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enum A
- B=0
- C=1
- D=2
- End Enum
- Enum.GetName(typeof(A), A.C) == "C"
- A.C.ToString() == "C"
- ((A)Enum.Parse(typeof(A), "C")) == A.C
- Module Example
- Public Sub Main()
- Dim colorStrings() As String = {"0", "2", "8", "blue", "Blue", "Yellow", "Red, Green"}
- For Each colorString As String In colorStrings
- Try
- Dim colorValue As Colors = CType([Enum].Parse(GetType(Colors), colorString, True), Colors)
- If [Enum].IsDefined(GetType(Colors), colorValue) Or colorValue.ToString().Contains(",") Then
- Console.WriteLine("Converted '{0}' to {1}.", colorString, colorValue.ToString())
- Else
- Console.WriteLine("{0} is not an underlying value of the Colors enumeration.", colorString)
- End If
- Catch e As ArgumentException
- Console.WriteLine("{0} is not a member of the Colors enumeration.", colorString)
- End Try
- Next
- End Sub
- End Module
- A.C.name() == "C"
Add Comment
Please, Sign In to add comment