Main Content

Refer to a .NET Enumeration Member

You use an enumeration member in your code as an instance of an enumeration. To refer to an enumeration member, use the C# namespace, enumeration, and member names:

Namespace.EnumName.MemberName

For example, the System namespace in a .NET class library has a DayOfWeek enumeration. The members of this enumeration are:

Enumeration members for class 'System.DayOfWeek':
    Sunday
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday

To create a variable with the value Thursday, type:

gameDay = System.DayOfWeek.Thursday;
whos
  Name     Size Bytes Class

  gameDay  1x1  104   System.DayOfWeek

Using the Implicit Constructor

The implicit constructor, Namespace.EnumName, creates a member with the default value of the underlying type. For example, the NetDocEnum.Range enumeration has the following members:

Enumeration members for class 'NetDocEnum.Range':
    Max
    Min

Type:

x = NetDocEnum.Range
whos x
x = 
0

  Name  Size  Bytes  Class

  x     1x1   104    NetDocEnum.Range

Related Topics