NOTE. I work in .NET 3.5 here.
Let's say I have examples of base / child classes with the following constructors:
public Person(string name, int age, string job, bool isMale)
{
Name = name;
Age = age;
Job = job;
IsMale = isMale;
}
public CollegeStudent(string name) : this(name, 18) {}
public CollegeStudent(string name, int age) : this(name, age, "Student") {}
public CollegeStudent(string name, int age, string job) : this(name, age, job, true) {}
public CollegeStudent(string name, int age, string job, bool isMale) : base(name, age, job, isMale) {}
Is the compiler smart enough to make sure that the only thing the child constructors do is relate to each other and ultimately just call the base constructor? So, can it just change the initializers of the "this" constructor to invoke the base constructor directly at compile time?
Thus, this would significantly change all of this under the hood:
public CollegeStudent(string name) : base(name, 18, "Student", true) {}
public CollegeStudent(string name, int age) : base(name, age, "Student", true) {}
public CollegeStudent(string name, int age, string job) : base(name, age, job, true) {}
public CollegeStudent(string name, int age, string job, bool isMale) : base(name, age, job, isMale) {}
I would like to write my constructors in the same way as the first section, since it is convenient, but I can just call the base constructor directly for each constructor if I just take on useless utility data.