Sort and Group in LINQ
- by Jono
I apologise in advance if this has been answered before; it seems so fundamental to me yet I haven't turned up the answer in any of my searches.
I have a list of string tuples, say (P1,P2)
I'd like to know if there's a LINQ statement where I could group by P1 (in ascending order), and have that group contain all the P2 values for the group (in descending order).
For input: ("A","B"), ("A","C"), ("D","B")
I'd like to get two groups: "A" and "D" (in that order, every time)
where group "A" contains "C" and "B" (in that order, every time) and group "D" contains, well, "B".
Is this possible with the built-in LINQ classes or do I need to iterate the groups and sort them myself? Sounds like hard work~