10.2 Class members
The members of a class consist of the members introduced by its class-member-declarations and the members inherited from the direct base class.
The members of a class are divided into the following categories:
- Constants, which represent constant values associated with the class (Section 10.3).
- Fields, which are the variables of the class (Section 10.4).
- Methods, which implement the computations and actions that can be performed by the class (Section 10.5).
- Properties, which define named characteristics associated with reading and writing those characteristics (Section 10.6).
- Events, which define notifications that can be generated by the class (Section 10.7).
- Indexers, which permit instances of the class to be indexed in the same way (syntactically) as arrays (Section 10.8).
- Operators, which define the expression operators that can be applied to instances of the class (Section 10.9).
- Instance constructors, which implement the actions required to initialize instances of the class (Section 10.10)
- Destructors, which implement the actions to be performed before instances of the class are permanently discarded (Section 10.12).
- Static constructors, which implement the actions required to initialize the class itself (Section 10.11).
- Types, which represent the types that are local to the class (Section 9.5).
Members that can contain executable code are collectively known as the function members of the class 0. The function members of a class are the methods, properties, events, indexers, operators, instance constructors, destructors, and static constructors of that class.
A class-declaration creates a new declaration space (Section 3.3), and the class-member-declarations immediately contained by the class-declaration introduce new members into this declaration space. The following rules apply to class-member-declarations:
- Instance constructors, destructors and static constructors must have the same name as the immediately enclosing class. All other members must have names that differ from the name of the immediately enclosing class.
- The name of a constant, field, property, event, or type must differ from the names of all other members declared in the same class.
- The name of a method must differ from the names of all other non-methods declared in the same class. In addition, the signature (Section 3.6) of a method must differ from the signatures of all other methods declared in the same class.
- The signature of an instance constructor must differ from the signatures of all other instance constructors declared in the same class.
- The signature of an indexer must differ from the signatures of all other indexers declared in the same class.
- The signature of an operator must differ from the signatures of all other operators declared in the same class.
The inherited members of a class (Section 10.2.1) are not part of the declaration space of a class. Thus, a derived class is allowed to declare a member with the same name or signature as an inherited member (which in effect hides the inherited member).