Initialization of structures with a constructor in C#
Forums:
var size = new Size(10, 10);
var point = new Point(5, 5);
var rect = new Rectangle(size, point);
struct Size {
public int width, height;
public Size (int width, int height) {
this.width = width;
this.height = height;
}
}
struct Point {
public int top, left;
public Point (int top, int left) {
this.top = top;
this.left = left;
}
}
struct Rectangle {
public Size size;
public Point point;
public Rectangle (Size size, Point point) {
this.size = size;
this.point = point;
}
}
- Log in to post comments