我有这样的东西
Dictionary<String, Profile > sto;
Run Code Online (Sandbox Code Playgroud)
其中 Profile 是具有不同属性的类(例如 int Ints)。现在我想知道是否有一个命令可以对整个字典中的所有整数求和。
你可以只使用Sum方法:
int sum = sto.Sum(x => x.Value.SomeIntProperty);
Run Code Online (Sandbox Code Playgroud)