Calling base class constructor in C#

If we derive a class from a base class and want to pass data from the constructor of the derived class to the constructor of the base class, it is necessary to call base constructor .

In the inheritance hierarchy, always the base class constructor is called first. In c#, the base keyword is used to access the base class constructor as shown below.

In the below code we declare a constructor in a derived class. We have used the ':base(...)' keyword after the constructor declaration with a specific parameter list.

class Account
        private string mCode;
        private string mName;
        private string mdescription;
        private double mBalance;

        public Account(string code, string name, string description, double balance)
            mCode = code;
            mName = name;
            mdescription = description;
            mBalance = balance;
        public Account()


class PartyAccount :Account
            private string mAddress;
	private string mPhone;
    public PartyAccount(string code, string name, string description, double balance, string address, string phone)
        : base(code, name, description, balance)
        mAddress = address;
        mPhone = phone;

    public PartyAccount()
        : base()


The above two constructors are written to initialize base class members. The parameterless constructor of the base class is executed when we instantiate the class without passing any parameters. The other base class constructor is executed when we pass parameters while instantiating the object.