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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -