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

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 (ie, no prefixed modifier)?


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 , which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal .

And for nested types:

Members of    Default member accessibility
----------    ----------------------------
enum          public
class         private
interface     public
struct        private

By default, the access modifier for a class is internal . That means to say, a class is accessible within the same assembly. But if we want the class to be accessed from other assemblies then it has to be made public.


From MSDN:

Top-level types , which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal .


Nested types , which are members of other types, can have declared accessibilities as indicated in the following table.

默认嵌套成员可访问性和允许辅助功能修改器

Source: Accessibility Levels (C# Reference) (December 6th, 2017)

链接地址: http://www.djcxy.com/p/21240.html

上一篇: 在类型ID可接受后,C ++中的“const”是什么?

下一篇: C#类和成员(字段,方法等)的缺省可见性?