我定義我的結構是這樣的:有什麼不對這種結構類型的定義
struct Test
{
private string assayName;
public string AssayName { get; set; }
private string oldUnitName;
public string OldUnitName { get; set; }
private string newUnitName;
public string NewUnitName { get; set; }
public Test(string name, string oldValue, string newValue)
{
assayName = name;
oldUnitName = oldValue;
newUnitName = newValue;
}
}
,但它給了我下面的錯誤:
"Error 13 Backing field for automatically implemented property 'EnterResults.frmApplication.Test.NewUnitName' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer."
對於初學者:編譯器不會假定'assayName'是支持字段對於'AssayName' ... –
您的屬性不訪問或變更支持字段。 – canon
在附註上,您可能想要使用'class',而不是'struct'。 –