X hits on this document





134 / 396

Chapter ‎18   Unsafe code

primary-no-array-creation-expression: literal simple-name parenthesized-expression member-access invocation-expression element-access this-access base-access post-increment-expression post-decrement-expression object-creation-expression delegate-creation-expression typeof-expression checked-expression unchecked-expression

Primary expressions are divided between array-creation-expressions and primary-no-array-creation-expressions. Treating array-creation-expression in this way, rather than listing it along with the other simple expression forms, enables the grammar to disallow potentially confusing code such as

object o = new int[3][1];

which would otherwise be interpreted as

object o = (new int[3])[1];

7.5.1 Literals

A primary-expression that consists of a literal (§‎2.4.4) is classified as a value.

7.5.2 Simple names

A simple-name consists of a single identifier.

simple-name: identifier

A simple-name is evaluated and classified as follows:

If the simple-name appears within a block and if the block’s (or an enclosing block’s) local variable declaration space (§‎3.3) contains a local variable or parameter with the given name, then the simple-name refers to that local variable or parameter and is classified as a variable.

Otherwise, for each type T, starting with the immediately enclosing class, struct, or enumeration declaration and continuing with each enclosing outer class or struct declaration (if any), if a member lookup of the simple-name in T produces a match:

If T is the immediately enclosing class or struct type and the lookup identifies one or more methods, the result is a method group with an associated instance expression of this.

If T is the immediately enclosing class or struct type, if the lookup identifies an instance member, and if the reference occurs within the block of an instance constructor, an instance method, or an instance accessor, the result is the same as a member access (§‎7.5.4) of the form this.E, where E is the simple-name.

Otherwise, the result is the same as a member access (§‎7.5.4) of the form T.E, where E is the simple-name. In this case, it is a compile-time error for the simple-name to refer to an instance member.

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

Document info
Document views547
Page views547
Page last viewedTue Oct 25 01:39:46 UTC 2016