X hits on this document





222 / 396

Chapter ‎18   Unsafe code

class A { public const int X = B.Z + 1; public const int Y = 10; }

class B { public const int Z = A.Y + 1; }

the compiler first evaluates A.Y, then evaluates B.Z, and finally evaluates A.X, producing the values 10, 11, and 12. Constant declarations may depend on constants from other programs, but such dependencies are only possible in one direction. Referring to the example above, if A and B were declared in separate programs, it would be possible for A.X to depend on B.Z, but B.Z could then not simultaneously depend on A.Y.

10.4 Fields

A field is a member that represents a variable associated with an object or class. A field-declaration introduces one or more fields of a given type.

field-declaration: attributesopt   field-modifiersopt   type   variable-declarators   ;

field-modifiers: field-modifier field-modifiers   field-modifier

field-modifier: new public protected internal private static readonly volatile

variable-declarators: variable-declarator variable-declarators   ,   variable-declarator

variable-declarator: identifier identifier   =   variable-initializer

variable-initializer: expression array-initializer

A field-declaration may include a set of attributes (§‎17), a new modifier (§‎10.2.2), a valid combination of the four access modifiers (§‎10.2.3), and a static modifier (§‎10.4.1). In addition, a field-declaration may include a readonly modifier (§‎10.4.2) or a volatile modifier (§‎10.4.3) but not both. The attributes and modifiers apply to all of the members declared by the field-declaration. It is an error for the same modifier to appear multiple times in a field declaration.

The type of a field-declaration specifies the type of the members introduced by the declaration. The type is followed by a list of variable-declarators, each of which introduces a new member. A variable-declarator

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

Document info
Document views523
Page views523
Page last viewedMon Oct 24 14:23:31 UTC 2016