X hits on this document





304 / 396

Chapter ‎18   Unsafe code

enum-modifiers: enum-modifier enum-modifiers   enum-modifier

enum-modifier: new public protected internal private

It is a compile-time error for the same modifier to appear multiple times in an enum declaration.

The modifiers of an enum declaration have the same meaning as those of a class declaration (§‎10.1.1). Note, however, that the abstract and sealed modifiers are not permitted in an enum declaration. Enums cannot be abstract and do not permit derivation.

14.3 Enum members

The body of an enum type declaration defines zero or more enum members, which are the named constants of the enum type. No two enum members can have the same name.

enum-member-declarations: enum-member-declaration enum-member-declarations   ,   enum-member-declaration

enum-member-declaration: attributesopt   identifier attributesopt   identifier   =   constant-expression

Each enum member has an associated constant value. The type of this value is the underlying type for the containing enum. The constant value for each enum member must be in the range of the underlying type for the enum. The example

enum Color: uint { Red = -1, Green = -2, Blue = -3 }

results in a compile-time error because the constant values -1, -2, and –3 are not in the range of the underlying integral type uint.

Multiple enum members may share the same associated value. The example

enum Color { Red, Green, Blue,

Max = Blue }

shows an enum in which two enum members—Blue and Max—have the same associated value.

The associated value of an enum member is assigned either implicitly or explicitly. If the declaration of the enum member has a constant-expression initializer, the value of that constant expression, implicitly converted to the underlying type of the enum, is the associated value of the enum member. If the declaration of the enum

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.291

Document info
Document views425
Page views425
Page last viewedSat Oct 22 16:08:27 UTC 2016