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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -