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.2 Accessibility domains Paragraph 11 The accessibility domain of a member consists of the (possibly disjoint) sections of program text in which access to the member is permitted. 2 For purposes of defining the accessibility domain of a member, a member is said to be top-level if it is not declared within a type, and a member is said to be nested if it is declared within another type. 3 Furthermore, the text of an assembly is defined as all source text contained in all source files of that assembly, and the source text of a type is defined as all source text contained between the opening and closing "{" and "}" tokens in the class-body, struct-body, interface-body, or enum-body of the type (including, possibly, types that are nested within the type). Paragraph 21 The accessibility domain of a predefined type (such as object, int, or double) is unlimited. Paragraph 31 The accessibility domain of a top-level type T that is declared in a program P is defined as follows: [Note: From these definitions it follows that the accessibility domain of a top-level type is always at least the program text of the program in which that type is declared. end note] Paragraph 41 The accessibility domain of a nested member M declared in a type T within a program P, is defined as follows (noting that M itself may possibly be a type): [Note: From these definitions it follows that the accessibility domain of a nested member is always at least the program text of the type in which the member is declared. Furthermore, it follows that the accessibility domain of a member is never more inclusive than the accessibility domain of the type in which the member is declared. end note] [Note: In intuitive terms, when a type or member M is accessed, the following steps are evaluated to ensure that the access is permitted: [Example: In the example
public class A  
{  
   public static int X;  
   internal static int Y;  
   private static int Z;  
}  
internal class B  
{  
   public static int X;  
   internal static int Y;  
   private static int Z;  
   public class C  
   {  
      public static int X;  
      internal static int Y;  
      private static int Z;  
   }  
   private class D  
   {  
      public static int X;  
      internal static int Y;  
      private static int Z;  
   }  
}  
the classes and members have the following accessibility domains:
As the example illustrates, the accessibility domain of a member is never larger than that of a containing type. For example, even though all X members have public declared accessibility, all but A.X have accessibility domains that are constrained by a containing type. end example] Paragraph 51 As described in §10.4, all members of a base class, except for instance constructors, destructors, and static constructors are inherited by derived types. 2 This includes even private members of a base class. 3 However, the accessibility domain of a private member includes only the program text of the type in which the member is declared. [Example: In the example
class A  
{  
   int x;  
   static void F(B b) {  
      b.x = 1;   // Ok  
   }  
}  
class B: A  
{  
   static void F(B b) {  
      b.x = 1;   // Error, x not accessible  
   }  
}  
the B class inherits the private member x from the A class. Because the member is private, it is only accessible within the class-body of A. Thus, the access to b.x succeeds in the A.F method, but fails in the B.F method. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS