c# - Get an item from a IGrouping based on the highest date -


in ienumerable<appointment> contains appointments defined as:

class appointment {   public string name { get; set; }   public datetime lastmodified { get; set; }   public bool iscancelled { get; set; } } 

which in practice can like:

"jon s" | 25-02-2011 16:14:40 | true "jon s" | 25-04-2011 22:15:44 | false "marc g" | 15-11-2011 16:09:00 | true "marc g" | 21-12-2011 16:11:00 | false "marc g" | 20-12-2011 16:24:00 | true "eric l" | 13-06-2011 19:10:00 | false "reed c" | 13-04-2011 09:10:00 | true "reed c" | 13-06-2011 19:10:00 | false "john g" | 04-01-2011 06:12:00 | true "jon s" | 25-03-2011 12:24:42 | true 

this collection has downsized collection contains the appointments highest date lastmodified of each distinct name.

"jon s" | 25-04-2011 22:15:44 | false "marc g" | 21-12-2011 16:11:00 | false "eric l" | 13-06-2011 19:10:00 | false "reed c" | 13-06-2011 19:10:00 | false "john g" | 04-01-2011 06:12:00 | true 

i bit confused how this. when tried:

 .groupby(n => n.name)  .select(d => d.max(t => t.lastmodified)); 

it seems deliver correct dates, whole entity needed, missing?.

update/note: large collection 10.000 unsorted items, delivered service i cannot modify. each distinct group has 20 elements.

.groupby(n => n.name) .select(d => d.orderbydescending(t => t.lastmodified).first()) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -