I have defined my struct like this:
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;
}
}
but it gives me the following error:
“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.”
Well, there are two issues really:
1.Your using automatic properties, but then also providing fields, there is no wiring between the two.
2.When you use automatic properties, because this is a struct, they have to be initialised first. You can do this with a call to the default constructor. So a revised version would be: