Default visibility for C# classes and members (fields, methods, etc.)? Ask Question

Default visibility for C# classes and members (fields, methods, etc.)? Ask Question

I'm trying to find a reference for the default visibility of various aspects of C#. Class types, fields, methods, enums, etc.

Can someone provide a list of these along with their default visibility (i.e., no prefixed modifier)?

ベストアンサー1

All of the information you are looking for can be found here and here (thanks Reed Copsey):

From the first link:

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

...

The access level for class members and struct members, including nested classes and structs, is private by default.

...

interfaces default to internal access.

...

Delegates behave like classes and structs. By default, they have internal access when declared directly within a namespace, and private access when nested.


From the second link:

Top-level types他の型にネストされていない は、内部またはパブリックのアクセスのみが可能です。これらの型のデフォルトのアクセシビリティは内部です

ネストされた型の場合:

デフォルトメンバーのアクセシビリティ
---------- ----------------------------
列挙型パブリック
クラスプライベート
インターフェース パブリック
構造体プライベート

おすすめ記事