Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 14 Expressionsprevious at this levelnext at this level 14.5 Primary expressionsprevious at this levelnext at this level 14.5.2 Simple namesprevious at this levelnext at this level 14.5.2.1 Invariant meaning in blocks Paragraph 11 For each occurrence of a given identifier as a simple-name in an expression, every other occurrence of the same identifier as a simple-name in an expression within the immediately enclosing block (§15.2) or switch-block (§15.7.2) must refer to the same entity. 2 This rule ensures that the meaning of a name in the context of an expression is always the same within a block. Paragraph 21 The example
class 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 of which includes the nested block in the if statement).
2 In contrast, the example
class 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.
Paragraph 31 Note that the rule of invariant meaning applies only to simple names. 2 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 (§14.5.4). [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 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. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS