C# 获取C中列表列表中所有[x]索引的最大值
如果我在C项目中有一个List对象,我如何获得该对象中每个List中所有[x]索引的最大值 为了澄清我的想法,如果我有目标:C# 获取C中列表列表中所有[x]索引的最大值,c#,.net,linq,list,max,C#,.net,Linq,List,Max,如果我在C项目中有一个List对象,我如何获得该对象中每个List中所有[x]索引的最大值 为了澄清我的想法,如果我有目标: List<List<double>> myList = ...... 所以,我需要得到值15,因为它是它们的最大值 谢谢, 当做 Aya使用以下最大索引值 List<List<double>> list = ... var maxIndex = list.Max( innerList => innerList.Cou
List<List<double>> myList = ......
所以,我需要得到值15,因为它是它们的最大值
谢谢,
当做
Aya使用以下最大索引值
List<List<double>> list = ...
var maxIndex = list.Max( innerList => innerList.Count - 1); // Gets the Maximum index value.
另见
按评论编辑
我需要每个列表中特定索引中的最大值
一个未优化的解决方案是使用以下查询
var index = 10;
var maxAtIndex10 = list.Max ( innerList => innerList[index]);
下面的查询是查找所有索引的最大值
var maxIndex = list.Max( innerList => innerList.Count);
var listMaxAtAllIndexes = Enumerable.Range(0,maxIndex).Select ( index => list.Max(innerList => index < innerList.Count ? innerList[index] : 0));
你所说的所有[x]索引的完整性到底是什么意思?你的问题不清楚。谢谢你的回复,但我不想知道每个列表的最大值。相反,我需要每个列表中特定索引中的最大值。
var index = 10;
var maxAtIndex10 = list.Max ( innerList => innerList[index]);
var maxIndex = list.Max( innerList => innerList.Count);
var listMaxAtAllIndexes = Enumerable.Range(0,maxIndex).Select ( index => list.Max(innerList => index < innerList.Count ? innerList[index] : 0));