如何计算另一个列表中的列表List <List <KeyValuePair <string,double >>>

Mon*_*RPG 4 c# list count nested-lists

现在这是示例列表:

List<List<KeyValuePair<string, double>>> dblWordFreqByCluster = 
    new List<List<KeyValuePair<string, double>>>();
Run Code Online (Sandbox Code Playgroud)

我想要的是在这个主列表中获取列表计数(dblWordFreqByCluster).这意味着获得List<KeyValuePair<string, double>>列表的数量.

我可以通过制作我不想要的foreach迭代来计算它们,因为我认为这会导致不必要的性能损失.

Ada*_*itt 15

使用LINQ你可以做到

int totalCount = dblWordFreqByCluster.Sum(c => c.Count);
Run Code Online (Sandbox Code Playgroud)

然而,这与使用foreach循环没有太大的不同,但它不那么冗长,也很容易阅读.