C# Call Constructor From Constructor

  1. public class A
  2. {
  3.     public A() { }
  4.  
  5.     public A(int i) : this() { }
  6.  
  7.     public A(int i, string s) : this(i) { }
  8. }
  9.  
  10. public class B : A
  11. {
  12.     public B() { }
  13.  
  14.     public B(int i) : base() { }
  15.  
  16.     public B(int i, string s) : base(i, s) { }
  17. }

Class A constructors call itself constructor by using this keyword. B is derived from A. Constructors of B call base constructors using base keyword.

Happy coding
m ant / Mechanical Ant