Thursday, 13 December 2012

Convert an Enum to String Vb.NET

Convert an Enum to String Vb.NET


Enum colors
    red
    blue
    green
End Enum


Private  Sub Convert_Enum_To_String()

         Dim strColor As String
         For Each strColor In Enum.GetNames(Type.GetType(colors))
             Console.WriteLine(strColor)
         Next

End Sub

Enum value type has Static method GetNames, Which will convert all enum constants to strings.

No comments:

Post a Comment