更新时间:2022-12-10 21:20:07
替换第一()
与取(2)
,并使用的SelectMany()
:
List<Booking> yetAnotherList =
list.GroupBy(row => row.TourOperator)
.SelectMany(g => g.OrderBy(row => row.DepDate).Take(2))
.ToList();
更新:忘记了的SelectMany
第一次。要扁平化的结果(其中的SelectMany
一样),否则你得到的名单 IEnumerables
。
Update: Forgot the SelectMany
the first time. You want to flatten the result (which SelectMany
does), otherwise you get a list of IEnumerables
.