c# - Collection was modified; enumeration operation may not execute -


i have code , giving me collection modified , cannot enumerate anymore, wasn't changing value:

public static void addtodictionary(string words, dictionary<int, int> dwords) {     if (dcache.containskey(words))     {         dictionary<int, int> _dwordcache = dcache[words];          //error right here         foreach (int _key in _dwordcache.keys)         {             int _value = _dwordcache[_key];              if (dwords.containskey(_key))             {                 dwords[_key] = (dwords[_key] + _value);             }             else             {                 dwords[_key] = _value;             }         }     } } 

i'm changing dwords , not changing _dwordcache. there 2 dictionaries. can understand if changing _dwordcache give me error parameter being changed.

are sure dcache[words] element not modified elsewhere while foreach running?


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -