C# struct

(1)struct要么不声明构造函数(会有一个默认的无参构造函数),要么声明有参构造函数,struct不支持显示声明无参构造函数.

(2)struct的构造函数支持重载.

(3)struct的所有构造函数内部必须对所有字段和属性赋值.

(4)使用struct的方法前,必须已经对所有字段赋过值.

struct ValPoint
{
    public int x;
    public int y;
    public ValPoint(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}
ValPoint vp;
vp.x = 1;
vp.y = 2;
ValPoint vp = new ValPoint();
原文地址:https://www.cnblogs.com/liliuwei/p/11271338.html