Can I inherit constructors?
You don't need to create loads of constructors, all with the same code; you create only one, but have the derived classes call the base constructor:
public class Base
{
public Base(Parameter p)
{
Init(p)
}
void Init(Parameter p)
{
// common initialisation code
}
}
public class Derived : Base
{
public Derived(Parameter p) : base(p)
{
}
}
Change the init function to it is the constructor for the base class, and then call it from the inherited objects like this:
public InheritedObject(Parameter p) : base(p)
{
}
The base constructor will be invoked before any code in the constructor itself runs.