访问修饰符(C# 编程指南)(链接)
下面这篇微软官方文档,介绍了C#中的public、private、protected、internal等访问修饰符:
Access Modifiers (C# Programming Guide)
文档中有两个地方,这里特别强调下:
Classes and structs declared directly within a namespace (in other words, that aren't nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.
也就是说,在命名空间下的一个类或结构体,如果没有声明访问修饰符,那么类或结构体的默认访问修饰符就是internal。
Class and struct members, including nested classes and structs, have private access by default.
也就是说,在类或结构体中定义的成员(包括字段、属性、方法、嵌套的类或结构体等),如果没有声明访问修饰符,那么成员的默认访问修饰符就是private。