我有这个功能:
ObservableCollection<TankstellenItem> completeList = new ObservableCollection<TankstellenItem>();
for(var j = 0; j < listItem.Count; j++)
{
foreach (FuelItem fItem in listItem.ToList()[j].Fuels)
{
Debug.WriteLine("HERE AGAIN: " + fItem.Price);
TankstellenItem newItem = new TankstellenItem();
ObservableCollection<FuelItem> fuelList = new ObservableCollection<FuelItem>();
newItem = listItem.ToList()[j];
newItem.Fuels = null;
fuelList.Add(fItem);
newItem.Fuels = fuelList;
completeList.Add(newItem);
Debug.WriteLine("PRICES: " + completeList.ToList()[0].Fuels[0].Price);
}
}
Debug.WriteLine("COMPLETELIST LENGTH: " + completeList.ToList()[0].Fuels[0].Price + " + " + completeList.ToList()[1].Fuels[0].Price);
结果是:
LISTITEM LENGTH: 1
HERE AGAIN: 1,699
PRICES: 1,699
HERE AGAIN: 1,529
PRICES: 1,529
COMPLETELIST LENGTH: 1,529 + 1,529
正如您在 foreach 中看到的,价格是不同的。但是在 for 方法之后,每个项目的输出只有 1,529。我不明白为什么会这样。