[英]Why can't I inherit from a private class / interface?
Why is this illegal in C#? 为什么在C#中这是非法的?
class Foo: Foo.BaseFoo //Circular base class dependency compile time error
{
private class BaseFoo {...}
...
}
I'm not arguing when this could be useful or not, but I'd like to know what are the reasons that would disallow such code to compile. 我不是在争论什么时候有用,但是我想知道是什么原因阻止了这些代码的编译。 A similar restriction happens with private interfaces. 私有接口也有类似的限制。
UPDATE UPDATE
Seeing that its a duplicate I'll center the question more in why this isn't valid with interfaces which seems more useful? 看到它是重复的,我将集中更多的问题,为什么这对于看起来更有用的接口无效?
And, what's more, why does it seem to be legal with the Roslyn preview as shown here 而且,更重要的是,为什么它似乎是法律与罗斯林预览如图所示这里
This is not a problem of the access modifier -that the class is private. 这不是访问修饰符的问题-该类是私有的。 This is a circular base class dependency. 这是循环基类依赖项。 You try to define a class called Foo
that inherits a nested class called BaseFoo
. 您尝试定义一个名为Foo
的类,该类继承了一个称为BaseFoo
的嵌套类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.