X hits on this document

951 views

0 shares

0 downloads

0 comments

213 / 396

C# LANGUAGE SPECIFICATION

Members that can contain executable code are collectively known as the function members of the class. 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 (§‎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 (§‎3.6) of a method must differ from the signatures of all other methods declared in the same class, and two methods declared in the same class may not have signatures that differ solely by ref and out.

The signature of an instance constructor must differ from the signatures of all other instance constructors declared in the same class, and two constructors declared in the same class may not have signatures that differ solely by ref and out.

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 (§‎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).

10.2.1 Inheritance

A class inherits the members of its direct base class. Inheritance means that a class implicitly contains all members of its direct base class, except for the instance constructors, destructors and static constructors of the base class. Some important aspects of inheritance are:

Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the members declared in B as well as the members declared in A.

A derived class extends its direct base class. A derived class can add new members to those it inherits, but it cannot remove the definition of an inherited member.

Instance constructors, destructors, and static constructors are not inherited, but all other members are, regardless of their declared accessibility (§‎3.5). However, depending on their declared accessibility, inherited members might not be accessible in a derived class.

A derived class can hide (§‎3.7.1.2) inherited members by declaring new members with the same name or signature. Note however that hiding an inherited member does not remove that member—it merely makes that member inaccessible directly through the derived class.

An instance of a class contains a set of all instance fields declared in the class and its base classes, and an implicit conversion (§‎6.1.4) exists from a derived class type to any of its base class types. Thus, a reference to an instance of some derived class can be treated as a reference to an instance of any of its base classes.

A class can declare virtual methods, properties, and indexers, and derived classes can override the implementation of these function members. This enables classes to exhibit polymorphic behavior wherein the actions performed by a function member invocation varies depending on the run-time type of the instance through which that function member is invoked.

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

Document info
Document views951
Page views951
Page last viewedThu Dec 08 10:46:56 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments