0
我有以下方法需要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;
}
你想如何比较数组元素?按价值还是身份? – hoodaticus
目前还不清楚您是否想用匹配的当前optedIn值更新传入的数组(示例),反之亦然 – Steve
当前数组的值始终为Name1,Name2,Name3。我关心如何根据用户在示例数组中传递的内容更新每个人的OptedIn值。 – generationalVision