Why can't a class extend its own nested class in C#?

前端 未结 6 1498
半阙折子戏
半阙折子戏 2020-12-08 14:25

For example:

public class A : A.B
{
    public class B { }
}

Which generates this error from the compiler:

Circular

6条回答
  •  悲&欢浪女
    2020-12-08 14:51

    I think the nesting is meant to represent that the nested type is part of the definition of the nesting type. With that interpretation, the limitation makes sense because at the time the compiler hits the definition of A, A.B is not yet defined, and even at the end of A, it is already defined in terms of A.B.

提交回复
热议问题