title: Best way to remove multiple items matching a predicate from a .NET Dictionary?
body: <p>I need to remove multiple items from a Dictionary.
  A simple way to do that is as follows :</p>
  <pre><code>  List&lt;string&gt; keystoremove= new List&lt;string&gt;();
    foreach (KeyValuePair&lt;string,object&gt; k in MyCollection)
       if (k.Value.Member==foo)
          keystoremove.Add(k.Key);
    foreach (string s in keystoremove)
          MyCollection.Remove(s);
  </code></pre>
  <p>The reason why I can't directly Remove the items in the foreach block is that this would throw an Exception (&quot;Collection was modified...&quot;)</p>
  <p>I'd like to do the following :</p>
  <pre><code> MyCollection.RemoveAll(x =&gt;x.Member==foo)
  </code></pre>
  <p>But the <code>Dictionary&lt;&gt;</code> class doesn't expose a <code>RemoveAll(Predicate&lt;&gt; Match)</code> method, like the <code>List&lt;&gt;</code> Class does.</p>
  <p>What's the best way (both performance wise and elegant wise) to do that?</p>