Constructor Chaining With Example In C#

  1. namespace Consolepractice {  
  2.     class Program {  
  3.         public static void Main(string[] args) {  
  4.             student on = new student("Soumalya""132""M""7278283469");  
  5.             Console.ReadKey();  
  6.         }  
  7.     }  
  8.     class student {  
  9.         private string _name;  
  10.         private string _roll;  
  11.         private string _gender;  
  12.         private string _phn;  
  13.         public student() {  
  14.             Console.WriteLine("default");  
  15.         }  
  16.         public student(string Name): this() {  
  17.             this._name = Name;  
  18.         }  
  19.         public student(string Name, string Roll): this(Name) {  
  20.             this._roll = Roll;  
  21.         }  
  22.         public student(string Name, string Roll, string Gender): this(Name, Roll) {  
  23.             this._gender = Gender;  
  24.         }  
  25.         public student(string Name, string Roll, string Gender, string Phn): this(Name, Roll, Gender) {  
  26.             this._phn = Phn;  
  27.         }  
  28.     }  
  29. }