Struct constructor with parameters : Constructor : Struct C# Examples


C# Examples » Struct » Constructor »

 

Struct constructor with parameters









    
using  System;

struct  Point
{
      public  int  x;
      public  int  y;
      public  Point(int  a,  int  b)  
      {
            x  =  a;
            y  =  b;
      }
}

class  MainClass
{
      static  void  Main()
      {
            Point  p1  =  new  Point();
            Point  p2  =  new  Point(5,  10);

            Console.WriteLine("{0},{1}",  p1.x,  p1.y);
            Console.WriteLine("{0},{1}",  p2.x,  p2.y);
      }
}
    
   
  
   



Output

0,0
5,10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Struct
» Constructor