I've never thought of doing this! However, it seems to work OK.
public class Outer
{
public class Inner : Outer
{
public override string ToString()
{
return "I'm an inner";
}
}
public override string ToString()
{
return "I'm an outer";
}
}
To test it:
static void Main(string[] args)
{
Outer o = new Outer();
Console.WriteLine(o);
Outer.Inner i = new Outer.Inner();
Console.WriteLine(i);
Console.WriteLine("\nPress ENTER to continue");
Console.ReadLine();
}
Without using 'using' statements you have to refer to it as Outer.Inner
so it's a bit long winded! I'd prefer to declare them sequentially for
ease of readability but it seems that the compiler can cope with it OK.
Martijn Mulder wrote:
A construction like this:
class Outer
{
class Inner:Outer
{
}
}
compiles without problem but does it introduce infinity?