In this blog, I am going to explain the concept of Constructor Chaining In C#. This detailed blog will cover the following topics:
- Introduction
- Constructors in C#
- Constructor Chaining In C#
- Benefits of Constructor Chaining
- Drawbacks of Constructor Chaining
- Conclusion
Constructors in C#
As per Microsoft, "When a class or struct is instantiated, its constructor is called. Constructors have the same name as the class or struct, and they usually initialize the data members of the new object".
As per Wikipedia, "In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables".
In simple words, a constructor is a special type of method that is automatically invoked when an instance of a class is created. Constructors are mostly used to initialize the private fields of a class while an instance of the class is being created.
Key Points
- A class can have any number of constructors.
- Constructors can also be overloaded.
- A constructor doesn't have any return type, not even void.
- Within a class, you can create one static constructor only.
- The compiler will automatically create a default constructor in a class when there is no constructor in the class.
Example
public class ConstructorInCSharp
{
public bool IsInitialized;
public ConstructorInCSharp()
{
IsInitialized = true;
}
}
class Program
{
static void Main()
{
ConstructorInCSharp myObj = new ConstructorInCSharp();
Console.WriteLine(myObj.IsInitialized);
Console.ReadLine();
}
}

Constructor Chaining in C#
In simple words, calling one constructor from another constructor is called constructor chaining in C#.
Syntax
public mySampleClass(): this() //Calls another constructor of the same class
public mySampleClass(): base() //Calls the base class constructor
1) Calling the same class constructor
A constructor can call another constructor in the same class using "this" keyword. The "this" keyword can be used with or without parameters. Any parameters in the constructor are available as parameters to "this" or as part of the expression.
Example



Join the conversation! Your thoughts help the community grow.