C#: How to inherit constructors?

Posted by Ian Boyd on Stack Overflow See other posts from Stack Overflow or by Ian Boyd
Published on 2008-10-21T18:59:47Z Indexed on 2010/05/04 19:18 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about language