vb.net 4.0中字典的整数值字段的总和 [英] Sum integer value fields of a dictionary in vb.net 4.0

查看:464
本文介绍了vb.net 4.0中字典的整数值字段的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.net 4.0字典中,我知道我可以计算所有整数值字段的总和,如下所示:

In .net 4.0 dictionary I know I can calculate the sum of all integer value field like this:

 Dim dbar As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)() From {{"A", 1}, {"B", 1}, {"C", 1}}
    Dim sum As Integer = 0
    For Each v As Integer In dbar.Values
      sum += v
    Next

是否存在更优雅的方法来计算总和?

Does exist a more elegant way to do calculate the sum?

推荐答案

只需使用< a href =http://msdn.microsoft.com/en-us/library/bb338442.aspx> Sum() 方法:

Just use the Sum() method:

dbar.Values.Sum()

这篇关于vb.net 4.0中字典的整数值字段的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆