据我们所知
默认修饰符
- 类别
- 结构
- 委托(delegate)
- 界面
- 枚举
是内部。
枚举和接口(interface)成员默认是公共(public)。
默认情况下,Class、Struct 和 Delegate 成员都是私有(private)。
同一类库的非派生类可以访问公共(public)类和内部类 (以及公共(public)、内部、 protected 内部成员)。
不同类库的非派生类可以访问公共(public)类 (仅限公众成员)。
不同类库的派生类可以访问公共(public)类 (公共(public)、 protected 、 protected 内部成员)。
现在我想了解核心概念,为什么是这样......
protected 成员的范围比内部成员更大?
最佳答案
来自docs :
protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.
关于c# - 面向对象编程基本概念(C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13063412/