为什么这个有效如何在结构体的构造函数中设置自动属性?
public struct MyStruct
{
public MyStruct(double value)
{
myField = value;
}
private double myField;
public double MyProperty
{
get
{
return myField;
}
set
{
myField = value;
}
}
}
,这是不是
public struct MyStruct
{
public MyStruct(double value)
{
MyProperty = value;
}
public double MyProperty
{
get;
set;
}
}
你确定它必须是一个结构而不是一个类吗? – RickNZ 2009-11-30 02:18:05
可能的重复:http://stackoverflow.com/questions/522280/c-how-can-i-set-the-value-of-auto-property-backing-fields-in-a-struct-construc – itowlson 2009-11-30 02:20:51
这是也可能重复poat:http://stackoverflow.com/questions/272153/why-is-it-necessary-to-call-this-on-a-struct-to-use-automatic-properties-in-c – 2009-11-30 02:22:59