Search code examples
c#inheritanceparametersabstract

Passing parameters to the base class constructor


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


Solution

  • 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.