What is the Constructor Chaining in C# dotnet
Loading
What is the Constructor Chaining in C# dotnet
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Jul 3, 2025, 7:57 PM
Why Use Constructor Chaining?
Chaining Within the Same Class (
this) :thiskeyword.thiskeyword must be the first statement in the constructor.Chaining to a Base Class Constructor (
base) :basekeyword.this, thebasekeyword must also appear as the first statement in the constructor.Person Class :
Personclass has two constructors:this("Unknown", 0).NameandAgeproperties.Employee Class :
Employeeclass inherits fromPersonand adds aDepartmentproperty.base("Employee", 25).base(name, age).Execution Flow :
Personobject, the default constructor calls the parameterized constructor, which initializes the properties.Employeeobject:Departmentproperty.Departmentproperty.Constructor chaining is especially useful in inheritance hierarchies where derived classes need to initialize properties defined in the base class.
Rajanikant HawaldarPosted Jul 3, 2025, 11:39 AM
https://www.c-sharpcorner.com/article/constructor-chaining2/
Sangeetha SPosted Jul 3, 2025, 6:29 AM
Constructor Chaining in C# is a technique where one constructor calls another constructor in the same class or in the base class. This helps avoid code duplication and keeps initialization logic centralized.
sasikala sPosted Jul 3, 2025, 5:22 AM
Constructor chaining in C# .NET is a technique where one constructor calls another constructor within the same class or a base class. This is primarily used to reduce code duplication and improve code reusability, as common initialization logic can be placed in a single constructor and then called by others.