C# · 12月 20, 2021

C# 默认访问修饰符

[MSDN]

Classes and structs that are not nested within other classes or structs can be either public or internal. A type declared as public is accessible by any other type. A type declared as internal is only accessible by types within the same assembly. Classes and structs are declared as internal by default unless the keyword public is added to the class deFinition,as in the prevIoUs example. Class or struct deFinitions can add the internal keyword to make their access level explicit. Access modifiers do not affect the class or struct itself — it always has access to itself and all of its own members.

[MSDN]

Interfaces,like classes,can be declared as public or internal types. Unlike classes,interfaces default to internal access. Interface members are always public,and no access modifiers can be applied.

Namespaces and enumeration members are always public,and no access modifiers can be applied.

Delegates have internal access by default.

Any types declared within a namespace or at the top level of a compilation unit (for example,not within a namespace,class,or struct) are internal by default,but can be made public.