X hits on this document





136 / 396

Chapter ‎18   Unsafe code

void F(bool b) { if (b) { x = 1.0; } else { int x; x = 1; } } }

is permitted because the name x is never used in the outer block.

Note that the rule of invariant meaning applies only to simple names. It is perfectly valid for the same identifier to have one meaning as a simple name and another meaning as right operand of a member access (§‎7.5.4). For example:

struct Point { int x, y;

public Point(int x, int y) { this.x = x; this.y = y; } }

The example above illustrates a common pattern of using the names of fields as parameter names in an instance constructor. In the example, the simple names x and y refer to the parameters, but that does not prevent the member access expressions this.x and this.y from accessing the fields.

7.5.3 Parenthesized expressions

A parenthesized-expression consists of an expression enclosed in parentheses.

parenthesized-expression: (   expression   )

A parenthesized-expression is evaluated by evaluating the expression within the parentheses. If the expression within the parentheses denotes a namespace, type, or method group, a compile-time error occurs. Otherwise, the result of the parenthesized-expression is the result of the evaluation of the contained expression.

7.5.4 Member access

A member-access consists of a primary-expression or a predefined-type, followed by a “.” token, followed by an identifier.

member-access: primary-expression   .   identifier predefined-type   .   identifier

predefined-type:  one of boolbytechardecimaldoublefloatintlong objectsbyteshortstringuintulongushort

A member-access of the form E.I, where E is a primary-expression or a predefined-type and I is an identifier, is evaluated and classified as follows:

If E is a namespace and I is the name of an accessible member of that namespace, then the result is that member and, depending on the member, is classified as a namespace or a type.

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

Document info
Document views1466
Page views1466
Page last viewedTue Jan 24 13:39:08 UTC 2017