web 2.0

Quick Enum Snippet. Get Values or Names based on Name or Value

Public Enum CCid
        A = 3
        D = 6
End Enum

'Get Name
Dim s As String = [Enum].GetName(GetType(CCid), 3)

'Get Value
Dim v As Integer = [Enum].Parse(GetType(CCid), "A")
However, I do it this way. Where I actually use the Enum Type and check to see if it exists first.
 

Tags: ,

VB.NET | Code Snippets