title: Modify a dictionary which I am iterating through
body: <pre><code>foreach(BruteforceEntry be in Entries.Values)
  {
      if (be.AddedTimeRemove &lt;= now)
          Entries.Remove(be.IPAddress);
      else if (be.Unbantime &lt;= now &amp;&amp; be.Unbantime.Day == DateTime.Now.Day)
          Entries.Remove(be.IPAddress);
  }
  </code></pre>
  
  <p>An exception was thrown:</p>
  
  <blockquote>
    <p>Collection was modified; enumeration operation may not execute.</p>
  </blockquote>
  
  <p>For some reason, it is not any more.</p>
  
  <p>I know you cannot remove something, while iterating through it this way. My question is: How do I solve it?</p>