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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -