我有以下方法,该方法接受MyExampleClass和id的数组。我试图解决的当前问题在该方法中有注释。
public void Update(MyExampleClass[] example, int id)
{
//get the current values
var current = GetCurrentMyExampleClassValues(id);
//Compare the example and current arrays
//Update the OptedIn value for each item in the current array with the OptedIn value from the example array.
//The result is our new updated array
//Note that current array will always contain 3 items - Name1, Name2, Name3,
//but the example array can contain any combination of the 3.
var newArray = PsuedoCodeDoStuff();
var result = _myService.Update(newArray);
}
private MyExampleClass[] GetCurrentMyExampleClassValues(int id)
{
var current = new MyExampleClass[]
{
new MyExampleClass {Name = "Name1", OptedIn = false },
new MyExampleClass {Name = "Name2", OptedIn = true },
new MyExampleClass {Name = "Name3", OptedIn = false }
};
return current;
}