There are times when you want to avoid duplicating code and want to reuse them when working on multiple constructors .
If you want to call other constructors from a constructor within the same class , you need to use the this keyword .
How to Call Other Constructors within the Same Class in C# ?
Below is a sample code snippet that demonstrates how to Call Other Constructors within the Same Class in C# ?
public class ACEmployee { public string Name { get; set; } public string Designtaion { get; set; } public bool Active { get; set; } public ACEmployee(string _Employee) { this.Name = _Employee; } // How to Call Other Constructors with in the Same Class in C# ? public ACEmployee(ACEmployee emp) : this(emp.Name) { } }
Leave a Reply