I have the following list:
var items = new List<Tuple<string, int, int>>()
{
Tuple.Create("A", 3, 0),
Tuple.Create("A", 5, 0),
Tuple.Create("B", 1, 0),
Tuple.Create("C", 1, 0),
Tuple.Create("C", 3, 0),
Tuple.Create("C", 2, 0),
Tuple.Create("C", 3, 1)
};
I have the following linq:
var results = (from item in items
group item by item.Item1 into groupedItems
let maxPriority = groupedItems.Max(item => item.Item2)
from element in groupedItems
where element.Item2 == maxPriority
select element).Distinct();
I am getting this:
Name Priority
A 5
B 1
C 3
C 3
I would like only distinct as follows:
Name Priority
A 5
B 1
C 3
Does anyone know how to modify the linq to do that? Thank you before hand.
Note: I am aware that Distinct has overloads that allow you to pass an IComparer. But I would like to avoid this if it can be done simpler on the linq statement itself. I am not stuck on using the Distinct statement neither.