May 11, 2002 - Outside-the-Range Enum Values | WebReference

May 11, 2002 - Outside-the-Range Enum Values

Yehuda Shiran May 11, 2002
Outside-the-Range Enum Values
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

An enumerated variable can assume values outside the range of its declared values. This is convenient if you want to combine two values to create a third one which is not defined as a member. Let's assume we have the following enumeration:

  enum tvNetworkType {
      ABC,
      CBS,
      NBC,
      FOX
    }
The following line demonstrates a combination of the members NBC and FOX:

  var tvCombination : tvNetworkType = tvNetworkType.NBC | tvNetworkType.FOX;
If you print the value of tvCombination above, you would get the value of 12 (the OR combination of 8 and 4).

To learn more about JScript .NET, go to Column 108, JScript .NET, Part II: Major Features.