May 9, 2002 - Defining the Enumeration's Discrete Values
May 9, 2002 Defining the Enumeration's Discrete Values Tips: May 2002
Yehuda Shiran, Ph.D.
|
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;
By default, the first member is initialized as zero. You can change it by setting its value explicitly. For example, you can decide that ABC
should be equal to 1
instead of zero:
enum tvNetworkType : byte {
ABC = 1,
CBS,
NBC,
FOX
}
You can initialize any member of the enumerated type. By default, each member is one more than the previous member, if not explicitly initialized. In the above example, CBS
is 2
, NBC
is 3
, and FOX
is 4
. You can initialize all of them as follows:
enum tvNetworkType : byte {
ABC = 1,
CBS = 2,
NBC = 4,
FOX = 8
}
To learn more on JScript .NET, go to Column 108, JScript .NET, Part II: Major Features.