A parameterized constructor : Constructor : Class C# Examples


C# Examples » Class » Constructor »

 

A parameterized constructor









    
using  System;  
  
class  MyClass  {  
    public  int  x;  
  
    public  MyClass(int  i)  {  
        x  =  i;  
    }      
}      
      
class  MainClass  {      
    public  static  void  Main()  {      
        MyClass  t1  =  new  MyClass(10);  
        MyClass  t2  =  new  MyClass(88);  
  
        Console.WriteLine(t1.x  +  "  "  +  t2.x);  
    }      
}
    
   
  
   



Output

10 88


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Constructor