Table of Contents12345678910111213141516171819202122232425NotesDownloadECMA-334 C# Language Specification17 Classes17.4 Fields
Paragraph 11A field is a member that represents a variable associated with an object or class.2A field-declaration introduces one or more fields of a given type.field-declaration : attributesoptfield-modifiersopttypevariable-declarators;field-modifiers : field-modifierfield-modifiersfield-modifierfield-modifier : newpublicprotectedinternalprivatestaticreadonlyvolatilevariable-declarators : variable-declaratorvariable-declarators,variable-declaratorvariable-declarator : identifieridentifier=variable-initializervariable-initializer : expressionarray-initializer
Paragraph 21A field-declaration may include a set of attributes (§24), a new modifier (§17.2.2), a valid combination of the four access modifiers (§17.2.3), and a static modifier (§17.4.1).2In addition, a field-declaration may include a readonly modifier (§17.4.2) or a volatile modifier (§17.4.3), but not both The attributes and modifiers apply to all of the members declared by the field-declaration.3It is an error for the same modifier to appear multiple times in a field declaration.
Paragraph 31The type of a field-declaration specifies the type of the members introduced by the declaration.2The type is followed by a list of variable-declarators, each of which introduces a new member.3A variable-declarator consists 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.
Paragraph 41The type of a field must be at least as accessible as the field itself (§10.5.4).
Paragraph 51The value of a field is obtained in an expression using a simple-name (§14.5.2) or a member-access (§14.5.4).2The value of a non-readonly field is modified using an assignment (§14.13).3The value of a non-readonly field can be both obtained and modified using postfix increment and decrement operators (§14.5.9) and prefix increment and decrement operators (§14.6.5).
Paragraph 61A field declaration that declares multiple fields is equivalent to multiple declarations of single fields with the same attributes, modifiers, and type.[Example: For example
class A
{
public static int X = 1, Y, Z = 100;
}
is equivalent to
class A
{
public static int X = 1;
public static int Y;
public static int Z = 100;
}