13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 14 Expressionsenclosing block (§15.2) or switch-block (§15.7.2) must refer to the same entity. [Note: This rule ensures thatthe meaning of a name is always the same within a block. end note][Example: The exampleclass Test{double x;void F(bool b) {x = 1.0;if (b) {int x = 1;}}}results in a compile-time error because x refers to different entities within the outer block (the extent ofwhich includes the nested block in the if statement). In contrast, the exampleclass Test{double x;}void F(bool b) {if (b) {x = 1.0;}else {int x = 1;}}is permitted because the name x is never used in the outer block. end example][Note: The rule of invariant meaning applies only to simple names. It is perfectly valid for the sameidentifier to have one meaning as a simple name and another meaning as right operand of a member access(§14.5.4). end note] [Example: 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 aninstance constructor. In the example, the simple names x and y refer to the parameters, but that does notprevent the member access expressions this.x and this.y from accessing the fields. end example]14.5.3 Parenthesized expressionsA 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 theexpression 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 containedexpression.139

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

Saved successfully!

Ooh no, something went wrong!