13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14 Expressions• When this is used in a primary-expression within an instance method or instance accessor of a class, itis classified as a value. The type of the value is the class within which the usage occurs, and the value isa 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 avariable. The type of the variable is the struct within which the usage occurs, and the variable representsthe struct being constructed. The this variable of an instance constructor of a struct behaves exactly thesame as an out parameter of the struct type—in particular, this means that the variable must bedefinitely 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, itis classified as a variable. The type of the variable is the struct within which the usage occurs, and thevariable represents the struct for which the method or accessor was invoked. The this variable of aninstance method of a struct behaves exactly the same as a ref parameter of the struct type.Use of this in a primary-expression in a context other than the ones listed above is a compile-time error. Inparticular, it is not possible to refer to this in a static method, a static property accessor, or in a variableinitializerof a field declaration.14.5.8 Base accessA base-access consists of the reserved word base followed by either a “.” token and an identifier or anexpression-list enclosed in square brackets:base-access:base . identifierbase [ expression-list ]A base-access is used to access base class members that are hidden by similarly named members in thecurrent class or struct. A base-access is permitted only in the block of an instance constructor, an instancemethod, or an instance accessor. When base.I occurs in a class or struct, I must denote a member of thebase class of that class or struct. Likewise, when base[E] occurs in a class, an applicable indexer mustexist in the base class.At compile-time, base-access expressions of the form base.I and base[E] are evaluated exactly as if theywere written ((B)this).I and ((B)this)[E], where B is the base class of the class or struct in whichthe construct occurs. Thus, base.I and base[E] correspond to this.I and this[E], except this isviewed as an instance of the base class.When a base-access references a virtual function member (a method, property, or indexer), thedetermination of which function member to invoke at run-time (§14.4.3) is changed. The function memberthat is invoked is determined by finding the most derived implementation (§17.5.3) of the function memberwith respect to B (instead of with respect to the run-time type of this, as would be usual in a non-baseaccess). Thus, within an override of a virtual function member, a base-access can be used to invoke theinherited implementation of the function member. If the function member referenced by a base-access isabstract, a compile-time error occurs.14.5.9 Postfix increment and decrement operatorspost-increment-expression:primary-expression ++post-decrement-expression:primary-expression --The operand of a postfix increment or decrement operation must be an expression classified as a variable, aproperty access, or an indexer access. The result of the operation is a value of the same type as the operand.If the operand of a postfix increment or decrement operation is a property or indexer access, the property orindexer must have both a get and a set accessor. If this is not the case, a compile-time error occurs.145

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!