Passing parameters to the base class constructor

N.Y picture N.Y · May 5, 2014 · Viewed 22.7k times · Source

If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?

Answer

BradleyDotNET picture BradleyDotNET · May 5, 2014

Like this:

public class DerivedClass : BaseClass
{
    public DerivedClass(int derivedParam, String baseParam):base(baseParam)
    {
    }
}

The base keyword here calls the base class constructor that matches the provided parameter overload.