title: Modifying the contents of a Dictionary in foreach loop
body: <p>I am trying to update the contents of a C# Dictionary in a foreach loop, when a certain condition is met.</p>
  
  <pre><code>foreach (KeyValuePair&lt;int, Corpus_22_04_2014_StreetTable_Row&gt; entry in id_StreetNameDictionary)
  {
      if(something_happens())
      {
           Corpus_22_04_2014_StreetTable_Row r = entry.Value;
           //Modify r
           id_StreetNameDictionary[entry.Key] = r;
      }
  }
  </code></pre>
  
  <p>This throws an InvalidOperationException stating that "Collection was modified; enumeration operation may not execute.". It seems that we are not allowed to modify the contents of a Dictionary in foreach loop.</p>
  
  <p>What can be a possible workaround to that?</p>