C#: How to inherit constructors?
- by Ian Boyd
Imagine a base class with many constructors and a virtual method
public class Foo
{
...
public Foo() {...}
public Foo(int i) {...}
...
public virtual void SomethingElse() {...}
...
}
and now I want to create a descendant class that overrides the virtual method:
public class Bar : Foo
{
public override void SomethingElse() {...}
}
And another descendant that does some more stuff:
public class Bah : Bar
{
public void DoMoreStuff() {...}
}
Do I really have to copy all constructors from Foo into Bar and Bah? And then if I change a constructor signature in Foo, do I have to update it in Bar and Bah?
Is there no way to inherit constructors? Is there no way to encourage code reuse?