我正在学习 LINQ,我想从以下列表中找到最便宜的产品:
List<Product> products = new List<Product> {
new Product {Name = "Kayak", Price = 275M, ID=1},
new Product {Name = "Lifejacket", Price = 48.95M, ID=2},
new Product {Name = "Soccer ball", Price = 19.50M, ID=3},
};
我想出了以下方法,但不知何故感觉这不是最好的方法:
var cheapest = products.Find(p => p.Price == products.Min(m => m.Price));
你能告诉我实现这一目标的正确方法吗?