O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting Enumerations to Other Types

In many cases, it might make sense to convert an enumeration element to its underlying type—for example, when writing the value of an Enum variable to a database. In certain cases, it is also necessary to determine the value of an Enum element based on its name, which is a string, or to convert an Enum element value to its associated element name (a string).

Converting to Numeric Values and Vice Versa

It’s important to understand that, to the .NET Framework, an Enum is not a simple numeric value; it’s a type. To convert an Enum element to its value (or back if necessary), you must do the following (the example below still assumes that the Enum data type is Short):

Dim locContacts As ContactCategory Dim locShort ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required