Can someone give me 1 good reason why in C # the called constructor is always called before any of the constructor body?
.NET allows you to call a chain constructor anywhere in the constructor, so why does C # force you to do this before your constructor body is executed?
I once wrote to Anders X and asked him about it, and he was kind enough to spend time answering, no matter how busy he was. Unfortunately, he managed to answer a question that I really did not ask (about the named constructors.)
So, just out of curiosity, I thought I would ask here, because personally I don’t think there is one good reason for this restriction, so I hope they will re-educate me :-)
Just to clarify. The rule of CLR.NET is that 1 constructor must be called, only 1 constructor, and only once. So in CLR they are valid
public class Meh
{
public Meh()
{
Console.WriteLine("Meh()");
this("Hello");
}
public Meh(string message)
{
Console.WriteLine("Meh {0}", message);
base();
}
}
But not in C #
source
share