Wednesday, April 12, 2023

What is Constructor Chaining in C#

 Calling Constructor from another Constructor:


  1. public class mySampleClass  
  2. {  
  3.     public mySampleClass(): this(10)  
  4.     {  
  5.     // No parameter constructor method.// First Constructor  
  6.     }  
  7.   
  8.     public mySampleClass(int Age)   
  9.     {  
  10.     // Constructor with one parameter.// Second Constructor}  
  11.     }  
  12. }

No comments:

Post a Comment