Struct constructor with parameters : Constructor « struct « C# / CSharp Tutorial






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);
   }
}
0,0
5,10








6.3.Constructor
6.3.1.Use method to init struct member variables
6.3.2.Struct constructor with parameters
6.3.3.Structs with constructors
6.3.4.Fraction struct