manWeddaweertyjj
New Member
I am trying to search through a dictionary to see if it has a certain value and if so then to change it. Here is my code:\[code\]foreach (var d in dictionary){ if (d.Value =http://stackoverflow.com/questions/15527900/="red") { d.Value = "http://stackoverflow.com/questions/15527900/blue"; }}\[/code\]In visual studio when i step through the code debugging it i can see it change the value then when it hits the foreach loop to reiterate again it throws an exception \[quote\] "Collection was modified; enumeration operation may not execute"\[/quote\]How do i fix this?