C# struct

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

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

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

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

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();
相关文章
相关标签/搜索