How do I select the item with the highest value using LINQ?
- by mafutrct
Imagine you got a class like this:
class Foo {
string key;
int value;
}
How would you select the Foo with the highest value from an IEnumeralbe<Foo>?
A basic problem is to keep the number of iterations low (i.e. at 1), but that affects readability. After all, the best I could find was something along the lines of this:
IEnumerable<Foo> list;
Foo max = list.Aggregate ((l, r) => l.value > r.value ? l : r);
Can you think of a more better way?