だから私はリストを持っており、私のメソッドでは変更を加えた新しいリストを返そうとしています。
ただし、問題は、手がかりのリストの Id に加えた変更が、渡す手がかりのリストにも加えられることです。
public List<Clue> NewOrderList(List<Clue> clues, int[] ids)
{
var newClueOrder = new List<Clue>();
// For each ID in the given order
for (var i = 0; i < ids.Length; i++)
{
// Get the original clue that matches the given ID
var clue = clues.First(clue1 => clue1.Id == ids[i]);
// Add the clue to the new list.
newClueOrder.Add(clue);
// Retain the ID of the clue
newClueOrder[i].Id = clues[newClueOrder.Count - 1].Id;
}
return newClueOrder;
}
これはなぜですか? また、これに対する最善の解決策は何ですか? 同様の質問を見たことがありますが、正直なところ、解決策が正確に何であるかはよくわかりませんでした。