Dictionary is a object that can store values in Key-Value pair. its just like a list, the only difference is:
List can be iterate using index(0-n) but not the Dictionary.
Generally when we try to iterate the dictionary we get below error:
“Collection was modified; enumeration operation may not execute.“
So How to parse a dictionary and modify its values??
To iterate dictionary we must loop through it’s keys or key – value pair.
<pre> //get key collection from dictionary into a list to loop through List<int> keys = new List<int>(Dictionary.Keys); // iterating key collection using simple for-each loop foreach (int key in keys) { // Now we can perform any modification with values of dictionary. Dictionary[key] = Dictionary[key] - 1; }</pre>