为什么私有类子类的用户不能访问私有类的公共成员数据?以下对我来说似乎非常违反直觉,因为它不会编译:
public class OuterClassBase {
private class PrivateInnerClass {
public void DoSomething () {}
}
protected class ProtectedInnerClass : PrivateInnerClass {}
}
public class OuterClassDerived : OuterClassBase {
public OuterClassDerived () {
ProtectedInnerClass o = new ProtectedInnerClass();
o.DoSomething(); // inaccessible due to its pretection level
}
}
公开PrivateInnerClass
/受保护允许代码编译...