Check if the backend value is defined for an Enum
Public Enum Status As Integer
Unknown = -3
Late = -1
OnTime = 0
Early = 1
End Enum
Module Example
Public Sub Main()
Dim values() As Integer = { -3, -1, 0, 1, 5, Int32.MaxValue }
For Each value In values
Dim status As Status
If [Enum].IsDefined(GetType(Status), value)
status = CType(value, Status)
Else
status = Status.Unknown
End If
Console.WriteLine("Converted {0:N0} to {1}", value, status)
Next
End Sub
End Module
Related examples in the same category