Scenario is very rare, but quite simple: you define a generic class, then create a nested class which inherits from outer class and define a associative field (of self type) wit
Inheriting from a generic parameterized with the current type is often called Curiously recurring template pattern and is discouraged by Eric Lippert, previously on the C# compiler team.
In your case, the nested class Outer.Inner
is defined as inheriting from Outer
. That means the nested class contains, through inheritance, a definition of a nested class. This yields an infinite definition of nested classes: Outer.Inner.Inner.Inner...
Now, in your original definition
class Inner : Outer
{
Inner field;
}
the field is declared as type Inner
which in this scope refers to the current type being defined. When you changed it to Inner.Inner
, the first Inner
referred to the current type being defined and the second .Inner
referred to the nested class obtained through inheritance.
As an example, let's expand the definition of the Inner class to include what is coming from the inheritance (and renaming to make things a little clearer):
//original
class Outer
{
class Inner1 //: Outer
{
Inner1 field;
//from inheritance
class Inner2 : Outer
{
Inner2 field;
}
}
}
//modified for Inner.Inner
class Outer
{
class Inner1 //: Outer
{
Inner1.Inner2 field;
//from inheritance
class Inner2 : Outer
{
Inner2.Inner3 field;
}
}
}
So back to your questions:
Why do we observe such behavior? Is the Inner.Inner type declaration has changed the type at all? Are Inner.Inner and Inner types differ in some way in this context?
You changed the type definition of class Inner so that its field is of a different type. An instance of Outer.Inner
would possibly (I have not verified) be castable to the other Inner type but they are 2 type definitions.