Sum values of multiple Dictionaries

I have many dictionaries with same keys and values are different. i want to create to new dictionary to have keys and sum of all values against every key.


Hi @muneeb,

Can you give me the sample input dictionaries with sample data and expected output…!



Please check the below code to add multiple dictionaries values with same key:

dictionaries.SelectMany(Function(d) d).GroupBy(Function(kvp) kvp.Key, Function(key, kvps) New With {Key
    .Key = key, Key
    .Value = kvps.Sum(Function(kvp) kvp.Value)
}).ToDictionary(Function(x) x.Key, Function(x) x.Value)

Where dictionaries is the array of the dictionary.

Hope it will work for you and resolve your issue!!! :grinning: :grinning:

Cheers @muneeb


@ParasTripathi Thanks man. I have resolved this issue with my own login