13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONThe value of a constant is obtained in an expression using a simple-name (§14.5.2) or a member-access (§14.5.4).A constant can itself participate in a constant-expression. Thus, a constant may be used in any construct thatrequires a constant-expression. [Note: Examples of such constructs include case labels, goto case statements,enum member declarations, attributes, and other constant declarations. end note][Note: As described in §14.15, a constant-expression is an expression that can be fully evaluated at compile-time.Since the only way to create a non-null value of a reference-type other than string is to apply the new operator,and since the new operator is not permitted in a constant-expression, the only possible value for constants ofreference-types other than string is null. end note]When a symbolic name for a constant value is desired, but when the type of that value is not permitted in aconstant declaration, or when the value cannot be computed at compile-time by a constant-expression, areadonly field (§17.4.2) may be used instead. [Note: The versioning semantics of const and readonly differ(§17.4.2.2). end-note]A constant declaration that declares multiple constants is equivalent to multiple declarations of single constantswith the same attributes, modifiers, and type. [Example: For exampleclass A{public const double X = 1.0, Y = 2.0, Z = 3.0;}is equivalent toclass A{public const double X = 1.0;public const double Y = 2.0;public const double Z = 3.0;}end example]Constants are permitted to depend on other constants within the same program as long as the dependencies arenot of a circular nature. The compiler automatically arranges to evaluate the constant declarations in theappropriate order. [Example: In the exampleclass 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. end example] Constant declarations may depend on constants from other programs, but suchdependencies are only possible in one direction. [Example: Referring to the example above, if A and B weredeclared in separate programs, it would be possible for A.X to depend on B.Z, but B.Z could then notsimultaneously depend on A.Y. end example]17.4 FieldsA field is a member that represents a variable associated with an object or class. A field-declaration introducesone or more fields of a given type.field-declaration:attributes opt field-modifiers opt type variable-declarators ;field-modifiers:field-modifierfield-modifiers field-modifier220

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!