我有订购产品的清单。我也有一个索引值列表。我想提取所有索引在索引列表中的产品。现在我正在这样做:
var indexes = new List<int> { 1, 2, 5, 7, 10 };
var myProducts = orderedProducts.Where((pr, i) => indexes.Any(x => x == i)).ToList();
但是,myProducts中只有2个元素:具有索引1和2的产品。它完全错过了5、7和10。这是怎么回事?我该如何解决?
注意:orderedProducts.Count始终大于indexes列表的最大值。
orderedProducts 由以下内容组成:
orderedProducts = productDictionary[fam.Key]
.ToList()
.OrderBy(g => g.factor)
.ToList();
其中g.factor,intfam.Key是产品字典的int密钥。我已经检查了myProducts,它确实是List<Product>按升序排序的。
prodDictionary是一个Dictionary<int?, List<Product>>。
萧十郎
长风秋雁
相关分类