Export (0) Print
Expand All

Enumerations Overview

Enumerations provide a convenient way to work with sets of related constants and to associate constant values with names. For example, you can declare an enumeration for a set of integer constants associated with the days of the week, and then use the names of the days rather than their integer values in your code.

You create an enumeration in the declarations section of a class or module, using the Enum statement.

An Enum type has a name, an underlying type, and a set of fields, each representing a constant. The name must be a valid Visual Basic .NET qualifier. The underlying type must be one of the integer types — Byte, Short, Long or Integer. Integer is the default. Enumerations are always strongly typed and are not interchangeable with integer number types.

You can assign the same value to multiple fields. When you do so, the compiler marks one of the Enum values as primary for purposes of string conversion and reflection. You can use an assignment statement to explicitly assign values to constants in an enumeration. All integer values, including negative numbers, are permissible.

For more information on using the Enum statement, see Declaring Enumerations.

See Also

Constants Overview | User-Defined Constants | Declaring Constants | Constant and Literal Data Types | Declaring Enumerations | Enumerations and Name Qualification | Intrinsic Constants and Enumerations

Show:
© 2014 Microsoft