Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello

I've got a list:

ID--------Date-----------NumValue
1---------2/2/2013----------0
1---------2/2/2013----------2
1---------1/1/2013----------4
2---------10/5/2009---------3
2---------01/01/2005--------4

I'd like to get back all the line items with the max(not necessarily one) date value

so the aim is to get back 0th 1 st 3 rd line
the weak attempt as follows:
C#
var plpo1 = (from y in plpo0
    group y by new { y.tervcsop, } into grouped
          let maxdate = grouped.Max(y => y.maxdate)
                          orderby maxdate descending
                                select new
                                {
                                    tcs = grouped.Key.tervcsop,
                                    md = maxdate,
                                    norm = grouped.Select(x => x.normaertek)

                                }).ToList();

                   var plpo2 = plpo1.Where(x => x.md == plpo1.Max(o => o.md));


thanks for sharing the ideas
Posted
Comments
Michiel du Toit 15-Feb-13 5:55am    
Please improve your question. You are already getting all items with the maximum values with your plpo2 assignment, what exactly do you want to do in addition?

1 solution

Try this one:

C#
var groups = testlist.GroupBy(a => (a.ID.ToString()));

groups.SelectMany(a => a.Where(b => b.Date == a.Max(c => c.Date)))


Let me know if it works.
 
Share this answer
 
Comments
gericooper 15-Feb-13 7:10am    
Awesome stuff, thank you....Will be studying SelectMany....
Motamas 15-Feb-13 8:18am    
It is really useful :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900