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 10 Basic conceptsprevious at this levelnext at this level 10.5 Member accessprevious at this levelnext at this level 10.5.3 Protected access for instance members Paragraph 11 When a protected instance member is accessed outside the program text of the class in which it is declared, and when a protected internal instance member is accessed outside the program text of the program in which it is declared, the access is required to take place through an instance of the derived class type in which the access occurs. 2 Let B be a base class that declares a protected instance member M, and let D be a class that derives from B. 3 Within the class-body of D, access to M can take one of the following forms: Paragraph 21 In addition to these forms of access, a derived class can access a protected instance constructor of a base class in a constructor-initializer (§17.10.1). [Example: In the example
public class A  
{  
   protected int x;  
   static void F(A a, B b) {  
      a.x = 1;   // Ok  
      b.x = 1;   // Ok  
   }  
}  
public class B: A  
{  
   static void F(A a, B b) {  
      a.x = 1;   // Error, must access through instance of B  
      b.x = 1;   // Ok  
   }  
}  
within A, it is possible to access x through instances of both A and B, since in either case the access takes place through an instance of A or a class derived from A. However, within B, it is not possible to access x through an instance of A, since A does not derive from B. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS