How to add all key value of a dictionary

Hello!
i have this dictionary variable : new Dictionary(of String, String) From {{“A”,10},{“B”,20}, {“C”, “30”},{“D”,40}}

is it possible to add the all the key value?if so how do i do it?
example : 10+20+30+40 = 100

thank you in advance!

Hi @ramadhani.sheffi

Try this blow expression

newValue = Cdbl(yourDictionaryVariable(“key”).Tostring) + Cdbl(yourDictionaryVariable(“key”).Tostring)

Regards
Gokul

Hi @ramadhani.sheffi ,

For a more dynamic approach to Sum up all of the Values of the Dictionary (Provided all values are numbers), we can use the below Expression :

myDict = new Dictionary(of String, String) From {{"A","10"},{"B","20"}, {"C", "30"},{"D","40"}}

TotalSum = myDict.Values.Sum(Function(x)CDbl(x))

Where TotalSum is of the data Type Double, myDict is of Data Type Dictionary(Of String,String)

2 Likes

It works! Thank you very much for the answer!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.