Constructor Chaining in C#

  1. namespace ConstructorChaining  
  2.   
  3. {  
  4.   
  5. class Employee  
  6.   
  7. {  
  8.   
  9. public string FirstName { getprivate set; }  
  10.   
  11. public string LastName { getprivate set; }  
  12.   
  13. public Employee()  
  14.   
  15. {  
  16.   
  17. this.FirstName = "Akshay";  
  18.   
  19. this.LastName = "Patel";  
  20.   
  21. }  
  22.   
  23. public Employee(string firstName)  
  24.   
  25. {  
  26.   
  27. this.FirstName = firstName;  
  28.   
  29. }  
  30.   
  31. public Employee(string firstName, string lastName) : this(firstName)  
  32.   
  33. {  
  34.   
  35. this.LastName = lastName;  
  36.   
  37. }  
  38.   
  39. }  
  40.   
  41. }  
  42.   
  43. Client:  
  44.   
  45. namespace ConstructorChaining  
  46.   
  47. {  
  48.   
  49. class Program  
  50.   
  51. {  
  52.   
  53. static void Main(string[] args)  
  54.   
  55. {  
  56.   
  57. Employee emp2 = new Employee("Ishu""Patel");  
  58.   
  59. Console.WriteLine(emp2.FirstName + " " + emp2.LastName);  
  60.   
  61. Console.ReadKey();  
  62.   
  63. }  
  64.   
  65. }  
  66.   
  67. }