Can I inherit constructors?

Viewed 95470

I know it's not possible to inherit constructors in C#, but there's probably a way to do what I want to do.

I have a base class that is inherited by many other classes, and it has an Init method that does some initializing taking 1 parameter. All other inheriting classes also need this initializing, but I'd need to create separate constructors for all of them that would like like this:

public Constructor(Parameter p) {
    base.Init(p);
}

That totally violates the DRY principles! How can I have all necessary stuff initialized without creating dozens of constructors?

6 Answers

The methods in the base class are automatically available in the derived class. All that is needed is to describe them as protected or public. Their signature does not need to be repeated in the derived class.

If the base class does not want them available, they will be marked private.

Since the constructors are missing this choice, this looks to be a deficiency in the C# language. Perhaps the language designers are unable to solve.

Related