c# - Selecting the newest entry of each day -
consider simple class
public class data { public datetime date; public object content; }
now have ienumerable<data>
called datas
, want linq sort older items of each day out. such if there items of same day, interested in latest item of day.
is possible linq?
here how can it:
var result = datas //group day (we don't include time here) .groupby(x => x.date.date) //for each group (day), recent item (we include time here) .select(g => g.orderbydescending(x => x.date).first()) .tolist();
for more readability, use x.timeofday
instead of x.date
in select
statement.
Comments
Post a Comment