『TaeheeLive's learning notes of C#.(1)默认构造器 与 值类型的构造器。』
//定义 值类型
struct SomeValueType
{
int x=87;//[错误]:结构中不能有实例字段初始值设定项。
}
//上面的会转换成 以下代码。
struct SomeValueType
{
int x;
public SomeValueType()//[错误]:结构不能包含显式的无参数构造函数。
{
this.x = 87;
}
}
struct SomeValueType//正确
{
int x;
}
struct SomeValueType//正确
{
int x;
public SomeValueType(int y)
{
this.x = y;
}
}
//总结:值类型 不允许有 无参构造器。