---
title: "How to call one constructor from another in C#?"  
description: "How to call one constructor from another in C#?"  
author: "Steilla Mitchel"  
published: 2023-07-12  
updated: 2023-07-13  
canonical: https://www.mindstick.com/forum/159052/how-to-call-one-constructor-from-another-in-c-sharp  
category: "c#"  
tags: ["c#", "class"]  
reading_time: 2 minutes  

---

# How to call one constructor from another in C#?

How to call [one constructor](https://www.mindstick.com/forum/159570/how-to-call-one-constructor-from-another) from another in C#?

## Replies

### Reply by Aryan Kumar

Sure, here is how to call one constructor from another in C#:

To call one constructor from another in C#, you can use the `this()` keyword. The `this()` keyword takes the name of the constructor that you want to call as a parameter.

For example, the following code calls the `Constructor1()` constructor from the `Constructor2()` constructor:

C#

```plaintext
class MyClass
{
    public MyClass()
    {
        // This is the default constructor.
    }

    public MyClass(string name)
    {
        // This constructor calls the default constructor.
        this();

        // This constructor also sets the `name` property.
        this.name = name;
    }

    private string name;
}
```

When the `Constructor2()` constructor is called, the `this()` keyword calls the `Constructor1()` constructor first. Then, the `Constructor2()` constructor sets the `name` property.

Here is an explanation of the code:

- The `this()` keyword is used to call the `Constructor1()` constructor.
- The `Constructor1()` constructor is the default constructor for the `MyClass` class.
- The `Constructor2()` constructor takes a `string` parameter called `name`.
- The `Constructor2()` constructor calls the `this()` keyword to call the `Constructor1()` constructor.
- The `Constructor2()` constructor also sets the `name` property.


---

Original Source: https://www.mindstick.com/forum/159052/how-to-call-one-constructor-from-another-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
