【发布时间】:2014-02-03 15:28:17
【问题描述】:
我有一个 SortedList 列表,我有兴趣找到对应于最长列表(其中包含最多项目的列表)的 KEY。在代码中,它看起来像:
// how the list is defined:
var myList = new SortedList<long, List<string>>();
// EXAMPLE data only:
myList.Add(0, new List<string>());
myList[0].AddRange(new []{"a", "b", "c"});
myList.Add(8, new List<string>());
myList[8].AddRange(new []{"1", "2"});
myList.Add(23, new List<string>());
myList[23].AddRange(new []{"c", "d", "e", "f", "g"});
在上面的示例中,结果应该是“23”,因为这是最长列表的键。
我知道如何用 for 循环来写这个,但我认为这应该是用 LINQ 做的简单。也就是说,我似乎无法完全正确地使用语法!任何帮助表示赞赏!
【问题讨论】:
标签: c# linq sortedlist