如何计算在不包括第一项的值的字典中的所有值的总和? [英] How to calculate the sum of all values in a dictionary excluding the first item's value?
本文介绍了如何计算在不包括第一项的值的字典中的所有值的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的(字符串,十进制)字典和需要计算从第二项开始的所有值(十进制值)的总和。它是实现使用LINQ
I have a dictionary of (string, decimal) and need to calculate the sum of all the Values (decimal values) starting from the second item. Is it achievable using LINQ?
推荐答案
非常实现使用LINQ:
Very achievable using LINQ:
myDict.Skip(1).Sum(x => x.Value);
然而,标准的词典
类没有按'项目ŧ保证顺序,因此,第一的项目可以是任何东西。
However, the standard Dictionary
class doesn't guarantee ordering of items, so the "first" item can be anything.
这篇关于如何计算在不包括第一项的值的字典中的所有值的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文