spacer
Yehuda Shiran May 9, 2002
Defining the Enumeration's Discrete Values
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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;
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.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint