爲什麼這個有效如何在結構體的構造函數中設置自動屬性?
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