我有一個列表OneStopPrice; MultiStopPrice; NonStopPrice
列表。我希望所有3列都有Min()
。但是如果任何列的Min()
爲0,則必須忽略它。Linq Min()的非零值
OneStop | NonStop | MultiStop
-----------------------------
233.23 | 0.0 | 355.23
這裏NonStop必須被視爲最高值,以便忽略它。
任何人都有想法使用LinQ
?
我已經使用查詢,如下所示:
var data = odyResults.GroupBy(logEle => new { logEle.Air.FromCity, logEle.Air.ToCity }, (key, group) => new{
FromCity = key.FromCity,
ToCity = key.ToCity,
OneStopPrice = group.Min(x=>x.Air.OneStopPrice),
MultiStopPrice = group.Min(x => x.Air.MultiStopPrice),
NonStopPrice = group.Min(x => x.Air.NonStopPrice),
FromToCityCount = group.Count()
});
你說的*忽略*是什麼意思?屬性不應該出現在匿名對象中? –
'group.Where(c => c.OneStopPrice!= 0).Min(c => c.OneStopPrice)'?不知道,你正在嘗試做什麼,但。 – Leri
忽略意味着我希望接近最低值。意味着非零值的Min()。 –