Constructor Chaining in C# with this() Keyword – Real Example Explained

Constructor Chaining in C# with this() Keyword – Real Example Explained

Constructor chaining is one of the most important Object Oriented Programming concepts in C#. It allows one constructor to call another constructor inside the same class using the this() keyword. This helps avoid duplicate code and keeps object initialization clean and consistent.

Watch the Full Video Explanation

Here is the complete video where I explain constructor chaining step by step with this exact program:

The C# Program Used in This Video


namespace ConstructorChaining
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person("Sudipto","Male",DateTime.Parse("07-Jul-1980"));

            p.Display();
            Console.ReadKey();
        }
    }

    class Person
    {
        private int personId;
        private string personName;
        private string gender;
        private DateTime dob;

        // Default constructor
        public Person()
        {
            this.personId = DateTime.Now.Microsecond;    
        }

        // Parameterized constructor 1
        public Person(string personName) : this()
        {
            this.personName = personName;
        }

        // Parameterized constructor 2
        public Person(string personName, string gender) : this(personName)
        {
            this.gender = gender;
        }

        // Parameterized constructor 3
        public Person(string personName, string gender, DateTime dob) : this(personName, gender)
        {
            this.dob = dob;
        }

        public void Display()
        {
            Console.WriteLine("Person Id: " + this.personId);
            Console.WriteLine("Name: " + this.personName);
            Console.WriteLine("Gender: " + this.gender);
            Console.WriteLine("DOB: " + this.dob);
        }
    }
}

How Constructor Chaining Works

When the following line executes:


Person p = new Person("Sudipto","Male",DateTime.Parse("07-Jul-1980"));

C# does not directly jump into the 3-parameter constructor. Instead, it follows this chain:

  • First it calls Person() (default constructor)
  • Then it calls Person(string)
  • Then it calls Person(string, string)
  • Finally it reaches Person(string, string, DateTime)

This happens because each constructor uses the this() keyword to forward the call to another constructor. So every object gets properly initialized step by step.

Why Constructor Chaining is Important

Without constructor chaining, you would need to repeat initialization logic like setting personId in every constructor. That leads to:

  • Duplicate code
  • Harder maintenance
  • Higher chance of bugs

Using constructor chaining ensures that shared initialization logic is written only once and reused safely.

About Me

I am Sudipto, a Microsoft-certified .NET trainer with over 20 years of experience. I provide 1-to-1 online and offline training in C#, ASP.NET Core, SQL Server, Web API and interview preparation.

Website: https://supernovaservices.com
WhatsApp: +91-9331897923

If you want to truly understand C# and .NET from first principles instead of just memorizing interview questions, feel free to contact me.

Class Guidelines for Effective 1-on-1 Learning

To keep every session productive and distraction-free, please follow these simple guidelines:

  • Quiet Environment: Join from a calm, private room with minimal background noise. Avoid public or noisy places.
  • No Interruptions: Inform family/roommates in advance. Keep doors closed during class.
  • Mobile on Silent / DND: Set your phone to Silent or Do Not Disturb to prevent calls and notifications.
  • Be Fully Present: Do not multitask. Avoid attending to other calls, visitors, or errands during the session.
  • Stable Setup: Use a laptop/desktop with a stable internet connection and required software installed (Visual Studio/.NET, SQL Server, etc.).
  • Punctuality: Join on time so we can utilize the full session effectively.
  • Prepared Materials (If any): Keep project files, notes, and questions ready for quicker progress.

Following these guidelines helps you focus better and ensures I can deliver the best learning experience in every class.

Schedule a Quick 10-Minute Call

I prefer to start with a short 10-minute free call so I can understand:

  • Your learning objectives and career goals
  • Your current skill level
  • The exact topics you want to learn

Why? Because course content, teaching pace, and fees all depend on your needs — there’s no “one-size-fits-all” pricing. Please leave your details below, and I’ll get back to you to arrange a convenient time for the call.




Note: Payment is made only after your first class, once you’re completely satisfied. However, fees paid after the first class are non-refundable. This helps maintain scheduling commitments and allows me to reserve your preferred time slot with full attention.

Google Review Testimonials

.NET Online Training
Average Rating: 4.9
Votes: 50
Reviews: 50