Linq表达式以查找List< List< int>> ;?的最大值? [英] Linq expression to find the max value of a List<List<int>>?
本文介绍了Linq表达式以查找List< List< int>> ;?的最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个很酷的Linq表达式来查找List<List<int>>
中的最大int值?
Is there a cool Linq expression to find the max int value in a List<List<int>>
?
当前正在做
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();
这篇关于Linq表达式以查找List< List< int>> ;?的最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文