INPUT
Dictionary 1
"a", "1"
"b", "2"
Dictionary 2
"a", "3"
"b", "4"
Dictionary 3
"a", "5"
"b", "6"
OUTPUT (Concatenation of the dictionaries above)
Final dictionary
"a", "9"
"b", "12"
I wrote a pseudo code for this :
- Create a Final empty dictionary.
- Loop over the list of dictionaries.
- Loop over the KeyValue pair.
- Check if the key exists in final dictionary. If yes then add the value from KeyValue pair to final dictionary. If not then add to dictionary the KeyValue pair
Since this requires two foreach loops is there a lync version in c# for this and also which doesn't throw any exception.
Some of the questions that i referred on stackoverflow was Combine multiple dictionaries into a single dictionary