Structs with constructors : Constructor : Struct C# Examples


C# Examples » Struct » Constructor »

 

Structs with constructors









    
using  System;

struct  Point
{
        int  x;
        int  y;
        
        Point(int  x,  int  y)
        {
                this.x  =  x;
                this.y  =  y;
        }
        public  override  string  ToString()
        {
                return(String.Format("({0},  {1})",  x,  y));
        }
}

class  MainClass
{
        public  static  void  Main()
        {
                Point[]  points  =  new  Point[5];
                Console.WriteLine("[2]  =  {0}",  points[2]);
        }
}
    
   
  
   



Output

[2] = (0, 0)


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Struct
» Constructor