Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 2.21 KB

accessibility-domain.md

File metadata and controls

35 lines (26 loc) · 2.21 KB
description title ms.date helpviewer_keywords ms.assetid
Accessibility Domain - C# Reference
Accessibility Domain
07/20/2015
accessibility domain [C#]
8af779c1-275b-44be-a864-9edfbca71bcc

Accessibility Domain (C# Reference)

The accessibility domain of a member specifies in which program sections a member can be referenced. If the member is nested within another type, its accessibility domain is determined by both the accessibility level of the member and the accessibility domain of the immediately containing type.

The accessibility domain of a top-level type is at least the program text of the project that it is declared in. That is, the domain includes all of the source files of this project. The accessibility domain of a nested type is at least the program text of the type in which it is declared. That is, the domain is the type body, which includes all nested types. The accessibility domain of a nested type never exceeds that of the containing type. These concepts are demonstrated in the following example.

Example

This example contains a top-level type, T1, and two nested classes, M1 and M2. The classes contain fields that have different declared accessibilities. In the Main method, a comment follows each statement to indicate the accessibility domain of each member. Notice that the statements that try to reference the inaccessible members are commented out. If you want to see the compiler errors caused by referencing an inaccessible member, remove the comments one at a time.

[!code-csharpcsrefKeywordsModifiers#4]

C# Language Specification

[!INCLUDECSharplangspec]

See also