X hits on this document

1042 views

0 shares

0 downloads

0 comments

73 / 396

C# LANGUAGE SPECIFICATION

Otherwise, if M is private, the access is permitted if it occurs within the type in which M is declared.

Otherwise, the type or member is inaccessible, and a compile-time error occurs.

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.C.Z is the program text of B.C.

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.

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.

As described in §‎3.4, all members of a base class, except for instance constructors, destructors and static constructors, are inherited by derived types. This includes even private members of a base class. However, the accessibility domain of a private member includes only the program text of the type in which the member is declared. In the example

60Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1042
Page views1042
Page last viewedSat Dec 10 10:08:22 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments