X hits on this document

761 views

0 shares

0 downloads

0 comments

141 / 396

C# LANGUAGE SPECIFICATION

The set of indexers provided by T is constructed. The set consists of all indexers declared in T or a base type of T that are not override declarations and are accessible in the current context (§‎3.5).

The set is reduced to those indexers that are applicable and not hidden by other indexers. The following rules are applied to each indexer S.I in the set, where S is the type in which the indexer I is declared:

If I is not applicable with respect to A (§‎7.4.2.1), then I is removed from the set.

If I is applicable with respect to A (§‎7.4.2.1), then all indexers declared in a base type of S are removed from the set.

If the resulting set of candidate indexers is empty, then no applicable indexers exist, and a compile-time error occurs. If the candidate indexers are not all declared in the same type, the indexer access is ambiguous, and a compile-time error occurs (this latter situation can only occur for an indexer access on an instance of an interface that has multiple direct base interfaces).

The best indexer of the set of candidate indexers is identified using the overload resolution rules of §‎7.4.2. If a single best indexer cannot be identified, the indexer access is ambiguous, and a compile-time error occurs.

The index expressions of the expression-list are evaluated in order, from left to right. The result of processing the indexer access is an expression classified as an indexer access. The indexer access expression references the indexer determined in the step above, and has an associated instance expression of P and an associated argument list of A.

Depending on the context in which it is used, an indexer access causes invocation of either the get-accessor or the set-accessor of the indexer. If the indexer access is the target of an assignment, the set-accessor is invoked to assign a new value (§‎7.13.1). In all other cases, the get-accessor is invoked to obtain the current value (§‎7.1.1).

7.5.7 This access

A this-access consists of the reserved word this.

this-access: this

A this-access is permitted only in the block of an instance constructor, an instance method, or an instance accessor. It has one of the following meanings:

When this is used in a primary-expression within an instance constructor of a class, it is classified as a value. The type of the value is the class within which the usage occurs, and the value is a reference to the object being constructed.

When this is used in a primary-expression within an instance method or instance accessor of a class, it is classified as a value. The type of the value is the class within which the usage occurs, and the value is a reference to the object for which the method or accessor was invoked.

When this is used in a primary-expression within an instance constructor of a struct, it is classified as a variable. The type of the variable is the struct within which the usage occurs, and the variable represents the struct being constructed. The this variable of an instance constructor of a struct behaves exactly the same as an out parameter of the struct type—in particular, this means that the variable must be definitely assigned in every execution path of the instance constructor.

When this is used in a primary-expression within an instance method or instance accessor of a struct, it is classified as a variable. The type of the variable is the struct within which the usage occurs, and the variable represents the struct for which the method or accessor was invoked. The this variable of an instance method of a struct behaves exactly the same as a ref parameter of the struct type.

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

Document info
Document views761
Page views761
Page last viewedSat Dec 03 00:30:37 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments