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.

Chapter 17 Classesfield-modifier:newpublicprotectedinternalprivatestaticreadonlyvolatilevariable-declarators:variable-declaratorvariable-declarators , variable-declaratorvariable-declarator:identifieridentifier = variable-initializervariable-initializer:expressionarray-initializerA field-declaration may include a set of attributes (§24), a new modifier (§17.2.2), a valid combination of thefour access modifiers (§17.2.3), and a static modifier (§17.4.1). In addition, a field-declaration may include areadonly modifier (§17.4.2) or a volatile modifier (§17.4.3), but not both The attributes and modifiers applyto all of the members declared by the field-declaration. It is an error for the same modifier to appear multipletimes in a field declaration.The type of a field-declaration specifies the type of the members introduced by the declaration. The type isfollowed by a list of variable-declarators, each of which introduces a new member. A variable-declaratorconsists of an identifier that names that member, optionally followed by an “=” token and a variable-initializer(§17.4.5) that gives the initial value of that member.The type of a field must be at least as accessible as the field itself (§10.5.4).The value of a field is obtained in an expression using a simple-name (§14.5.2) or a member-access (§14.5.4).The value of a non-readonly field is modified using an assignment (§14.13). The value of a non-readonly fieldcan be both obtained and modified using postfix increment and decrement operators (§14.5.9) and prefixincrement and decrement operators (§14.6.5).A field declaration that declares multiple fields is equivalent to multiple declarations of single fields with thesame attributes, modifiers, and type. [Example: For exampleclass A{public static int X = 1, Y, Z = 100;}is equivalent toclass A{public static int X = 1;public static int Y;public static int Z = 100;}end example]17.4.1 Static and instance fieldsWhen a field declaration includes a static modifier, the fields introduced by the declaration are static fields.When no static modifier is present, the fields introduced by the declaration are instance fields. Static fields221

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

Saved successfully!

Ooh no, something went wrong!