Once more I have returned from my ancestral homeland, after some weeks of sun, rain, storms, wind, calm, friends and family. I could certainly use another few weeks, but it is good to be back too.
Well, enough chit-chat; back to programming language design. Here's an interesting combination of subclassing with nesting. Before trying it, what do you think this program should output?
public class A<T> {
public class B : A<int> {
public void M() {
System.Console.WriteLine(typeof(T).ToString());
}
public class C : B { }
}
}
class MainClass {
static void Main() {
A<string>.B.C c = new A<string>.B.C();
c.M();
}
}
Should this say that T is int, string or something else? Or should this program not compile in the first place?
It turned out that the actual result is not what I was expecting at least. I learn something new about this language every day.
Can you justify either the actual behaviour or what you believe the behaviour should be? Note that appealing to the C# standard will not help you here because the standard gets it wrong.
I'll discuss how exactly the standard gets it wrong and what the justification is for the actual behaviour next time on FAIC.
[UPDATE: I have reviewed the standard more carefully. The standard is actually correct, but really hard to read. I'll post a full analysis on Monday.]