Is there a cool Linq expression to find the max int value in a List<List<int>>
?
Currently doing:
int maxValue = 0;
foreach(List<int> valueRow in values)
{
// linq expression to get max value
int value = valueRow.OfType<int>().Max();
if (value > maxValue)
{
maxValue = value;
}
}
You can use SelectMany()
for this which flattens the nested list, then you can just take the maximum of the resulting sequence:
int maxValue = values.SelectMany( x => x).Max();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With