May 8, 2002 - Defining the Enumeration Data Type | WebReference

May 8, 2002 - Defining the Enumeration Data Type

Yehuda Shiran May 8, 2002
Defining the Enumeration Data Type
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Symbolic names you declare within the enum statement are numbered sequentially, starting at zero. In the following example:

  enum tvNetworkType {
    ABC,
    CBS,
    NBC,
    FOX
  }
the enumerated values are:

  ABC = 0;
  CBS = 1;
  NBC = 2;
  FOX = 3;
You can declare the underlying type of enumerated variable to be any integral data type, i.e. one of the following: int, short, long, byte, uint, ushort, ulong, or sbyte.

By default, the underlying data type of an enumeration is int. To save space, you can declare the underlying type of tvNetworkType to be of type byte:

  enum tvNetworkType : byte {
    ABC,
    CBS,
    NBC,
    FOX
  }
To learn more on JScript .NET, go to Column 108, JScript .NET, Part II: Major Features.