我有一個航班的列表,我試圖用日期字段對它進行分組,然後選擇它進入每個組的最低價格。在結果我應該得到 每天最便宜的航班。如何按字段對列表進行分組,並通過linq選擇另一個字段的分組min?
(from flights in aFlightList
where flights.IsDeparture && flights.OnlyTour == "0" && flights.OnlyPhone == "0"
group flights by flights.FlightDateFull
into grouping
select grouping.OrderBy(a => a.FlightDateFull).First()).ToArray();
此代碼按日期分組列表,但無法獲得特價機票。 我試試這樣:
(from flights in aFlightList
where flights.IsDeparture && flights.OnlyTour == "0" && flights.OnlyPhone == "0"
group flights by flights.FlightDateFull
into grouping
select grouping.OrderBy(a => a.FlightDateFull).Min(d=>d.PriceView)).ToArray();
這樣就會出錯。
如何做到這一點?