Structures constructors (initializers) in C#
Forums:
struct Point {
public int x, y;
public Point() { } //<- Error
//has such constructor by default
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
var p1 = new Point(1, 2);
//p1.x is 1 and p1.y is 2
var p2 = new Point();
//p2.x is 0 and p2.y is 0
- Log in to post comments