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.
2 Likes
Hi @muneeb,
Can you give me the sample input dictionaries with sample data and expected output…!
Thanks!
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!!!
Cheers @muneeb
2 Likes