C# 获取字典中int值的总和<;字符串,列表<;int>&燃气轮机;()

C# 获取字典中int值的总和<;字符串,列表<;int>&燃气轮机;(),c#,linq,C#,Linq,如何获得每个列表中所有整数的总和 代码: var teamScoreDict=newdictionary() 示例数据: teamScoreDict.Add("Blue", new List<int>(){34,53,57,22,68,78,12,28}); teamScoreDict.Add("Red", new List<int>(){64,66,22,73,25,45,36,21}); teamScoreDict.Add(“蓝色”,新列表(){34,53,5

如何获得每个列表中所有整数的总和

代码:

var teamScoreDict=newdictionary()
示例数据:

teamScoreDict.Add("Blue", new List<int>(){34,53,57,22,68,78,12,28});

 teamScoreDict.Add("Red", new List<int>(){64,66,22,73,25,45,36,21});
teamScoreDict.Add(“蓝色”,新列表(){34,53,57,22,68,78,12,28});
添加(“红色”,新列表(){64,66,22,73,25,45,36,21});

这将创建一个新字典,其中包含团队名称和列表中所有值的总和

teamScoreDict.ToDictionary(k => k.Key, v => v.Value.Sum())

你先做了自己的研究吗?你能给我发一份关于你使用速记的教程吗。。。。我已经习惯了from“from X in Y where theverneedof X select X.I”的语法,但这似乎已经过时了……嗨@user2888973,看看这篇MSDN文章。这是关于查询语法(f.Something中的f)和方法语法(f=>f.Something)之间差异的一个很好的介绍
var sum = teamScoreDict.SelectMany(x => x.Value).Sum();
teamScoreDict.ToDictionary(k => k.Key, v => v.Value.Sum())