ECMA-334: 10.5.1 Declared accessibility
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Language Specification |
| © 2006 ECMA International |
10.5.1 Declared accessibility
The declared accessibility of a member can be one of the following:
- Public, which is selected by including a
publicmodifier in the member declaration. The intuitive meaning ofpublicis "access not limited".
- Protected, which is selected by including a
protectedmodifier in the member declaration. The intuitive meaning ofprotectedis "access limited to the containing class or types derived from the containing class".
- Internal, which is selected by including an
internalmodifier in the member declaration. The intuitive meaning ofinternalis "access limited to this program".
- Protected internal, which is selected by including both a
protectedand aninternalmodifier in the member declaration. The intuitive meaning ofprotected internalis "access limited to this program or types derived from the containing class".
- Private, which is selected by including a
privatemodifier in the member declaration. The intuitive meaning ofprivateis "access limited to the containing type". Depending on the context in which a member declaration takes place, only certain types of declared accessibility are permitted. Furthermore, when a member declaration does not include any access modifiers, the context in which the declaration takes place determines the default declared accessibility.
- Namespaces implicitly have
publicdeclared accessibility. No access modifiers are allowed on namespace declarations.
- Types declared in compilation units or namespaces can have
publicorinternaldeclared accessibility and default tointernaldeclared accessibility.
- Class members can have any of the five kinds of declared accessibility and default to
privatedeclared accessibility. [Note: A type declared as a member of a class can have any of the five kinds of declared accessibility, whereas a type declared as a member of a namespace can have onlypublicorinternaldeclared accessibility. end note]
- Struct members can have
public,internal, orprivatedeclared accessibility and default toprivatedeclared accessibility because structs are implicitly sealed. Struct members introduced in a struct (that is, not inherited by that struct) cannot haveprotectedorprotected internaldeclared accessibility. [Note: A type declared as a member of a struct can havepublic,internal, orprivatedeclared accessibility, whereas a type declared as a member of a namespace can have onlypublicorinternaldeclared accessibility. end note]
- Interface members implicitly have
publicdeclared accessibility. No access modifiers are allowed on interface member declarations.
- Enumeration members implicitly have
publicdeclared accessibility. No access modifiers are allowed on enumeration member declarations.