下面这篇微软官方文档,介绍了C#中的publicprivateprotectedinternal等访问修饰符:

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

 

相关文章:

猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2021-05-12
  • 2021-12-25
  • 2021-06-17
  • 2021-09-10
相关资源
相似解决方案