更新时间:2023-02-13 11:28:13
基本解决方案:
allItems.ForEach(x => x.Combination.FirstOrDefault(ele => ele.Index == 0).ItemCount -= 5);
如注释中所述,如果只有1个元素的索引为1,那么您可以做的是:
As mentioned in comment if there is only 1 element with index 1 then you can do is :
allItems.ForEach(x => x.Combination.First(ele => ele.Index == 0).ItemCount -= 5);
如果不确定给定索引是否存在于集合中,您可以做的是
If you are not sure that the given index exists in the collection you can do is
CombMin element = new CombMin();
int index = 25;//does not exists in the collection
element = allItems.FirstOrDefault(x => x.Combination.Any(ele => ele.Index == index));
if (element != null)
element.Combination.FirstOrDefault(ele => ele.Index == index).ItemCount -= 5;