Click here to Skip to main content
14,664,816 members
Rate this:
Please Sign up or sign in to vote.
See more:

I've got a list:


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:
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)


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

thanks for sharing the ideas
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this one:

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.
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100