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 17 Classesprevious at this levelnext at this level 17.2 Class membersprevious at this levelnext at this level 17.2.6 Nested typesprevious at this levelnext at this level 17.2.6.5 Access to private and protected members of the containing type Paragraph 11 A nested type has access to all of the members that are accessible to its containing type, including members of the containing type that have private and protected declared accessibility. [Example: The example
using System;  
class C   
{  
   private static void F() {  
      Console.WriteLine("C.F");  
   }  
   public class Nested   
   {  
      public static void G() {  
         F();  
      }  
   }  
}  
class Test   
{  
   static void Main() {  
      C.Nested.G();  
   }  
}  
shows a class C that contains a nested class Nested. Within Nested, themethod G calls the static method F defined in C, and F has private declared accessibility. end example]
Paragraph 21 A nested type also may access protected members defined in a base type of its containing type. [Example: In the example
using System;  
class Base   
{  
   protected void F() {  
      Console.WriteLine("Base.F");  
   }  
}  
class Derived: Base   
{  
   public class Nested   
   {  
      public void G() {  
         Derived d = new Derived();  
         d.F();    // ok  
      }  
   }  
}  
class Test   
{  
   static void Main() {  
      Derived.Nested n = new Derived.Nested();  
      n.G();  
   }  
}  
the nested class Derived.Nested accesses the protected method F defined in Derived's base class, Base, by calling through an instance of Derived. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS