dlr bug
[mcs.git] / docs / ecma334 / 17.2.6.4.xml
blob4195f1bbb419d9f5d2d8891a4fca1fd5ef1652e5
1 <?xml version="1.0"?>
2 <clause number="17.2.6.4" title="this access">
3   <paragraph>A nested type and its containing type do not have a special relationship with regard to <non_terminal where="14.5.7">this-access</non_terminal> (<hyperlink>14.5.7</hyperlink>). Specifically, this within a nested type cannot be used to refer to instance members of the containing type. In cases where a nested type needs access to the instance members of its containing type, access can be provided by providing the this for the instance of the containing type as a constructor argument for the nested type. <example>[Example: The following example <code_example><![CDATA[
4 using System;  
5 class C   
6 {  
7    int i = 123;  
8    public void F() {  
9       Nested n = new Nested(this);  
10       n.G();  
11    }  
12    public class Nested {  
13       C this_c;  
14       public Nested(C c) {  
15          this_c = c;  
16       }  
17       public void G() {  
18          Console.WriteLine(this_c.i);  
19       }  
20    }  
21 }  
22 class Test {  
23    static void Main() {  
24       C c = new C();  
25       c.F();  
26    }  
27 }  
28 ]]></code_example>shows this technique. An instance of C creates an instance of Nested, and passes its own this to Nested's constructor in order to provide subsequent access to C's instance members. end example]</example> </paragraph>
29 </clause>