X hits on this document

939 views

0 shares

0 downloads

0 comments

125 / 396

C# LANGUAGE SPECIFICATION

A member lookup of a name N in a type T is processed as follows:

First, the set of all accessible (§‎3.5) members named N declared in T and the base types (§‎7.3.1) of T is constructed. Declarations that include an override modifier are excluded from the set. If no members named N exist and are accessible, then the lookup produces no match, and the following steps are not evaluated.

Next, members that are hidden by other members are removed from the set. For every member S.M in the set, where S is the type in which the member M is declared, the following rules are applied:

If M is a constant, field, property, event, type, or enumeration member, then all members declared in a base type of S are removed from the set.

If M is a method, then all non-method members declared in a base type of S are removed from the set, and all methods with the same signature as M declared in a base type of S are removed from the set.

Finally, having removed hidden members, the result of the lookup is determined:

If the set consists of a single non-method member, then this member is the result of the lookup.

Otherwise, if the set contains only methods, then this group of methods is the result of the lookup.

Otherwise, the lookup is ambiguous, and a compile-time error occurs (this situation can only occur for a member lookup in an interface that has multiple direct base interfaces).

For member lookups in types other than interfaces, and member lookups in interfaces that are strictly single-inheritance (each interface in the inheritance chain has exactly zero or one direct base interface), the effect of the lookup rules is simply that derived members hide base members with the same name or signature. Such single-inheritance lookups are never ambiguous. The ambiguities that can possibly arise from member lookups in multiple-inheritance interfaces are described in §‎13.2.5.

7.3.1 Base types

For purposes of member lookup, a type T is considered to have the following base types:

If T is object, then T has no base type.

If T is an enum-type, the base types of T are the class types System.Enum, System.ValueType, and object.

If T is a struct-type, the base types of T are the class types System.ValueType and object.

If T is a class-type, the base types of T are the base classes of T, including the class type object.

If T is an interface-type, the base types of T are the base interfaces of T and the class type object.

If T is an array-type, the base types of T are the class types System.Array and object.

If T is a delegate-type, the base types of T are the class types System.Delegate and object.

7.4 Function members

Function members are members that contain executable statements. Function members are always members of types and cannot be members of namespaces. C# defines the following categories of function members:

Methods

Properties

Events

Indexers

User-defined operators

Instance constructors

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

Document info
Document views939
Page views939
Page last viewedWed Dec 07 22:57:08 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments