我定义我的结构是这样的:有什么不对这种结构类型的定义
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'。 –