Jeff Key

It works on my machine

Sponsors

My Job

My stuff

Old stuff

Useful Stuff

Accessibility Domains and you

Sometimes I forget nested type accessibility rules (can containing classes access private members of the nested types?). I recently stumbled upon a nice reference:

C# Language Specs: 3.5.2 Accessibility domains

Included is a great little example at the bottom that serves as a nice quick reference:

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:

  • The accessibility domain of A and A.X is unlimited.
  • The accessibility domain of A.Y, B, B.X, B.Y, B.C, B.C.X, and B.C.Y is the program text of the containing program.
  • The accessibility domain of A.Z is the program text of A.
  • The accessibility domain of B.Z and B.D is the program text of B, including the program text of B.C and B.D.
  • The accessibility domain of B.D.X and B.D.Y is the program text of B, including the program text of B.C and B.D.
  • The accessibility domain of B.D.Z is the program text of B.D.

Posted: Jan 15 2005, 12:54 PM by jeffreykey | with 4 comment(s)
Filed under:

Comments

Jeff Key said:

Sorry, unsuccessfully tried formatting the code three times to make it more readable.
# January 15, 2005 1:58 PM

Chris Frazier said:

http://PostXING.url123.com/main

Let PostXING do it for you. :)
# January 15, 2005 2:38 PM

Jeff Key said:

Godd stuff, thanks Chris.
# January 15, 2005 3:07 PM

david said:

GOD STUFF \m/
# January 15, 2005 5:38 PM