title: Deleting while iterating over a dictionary
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/2347269/modifying-net-dictionary-while-enumerating-through-it">Modifying .NET Dictionary while Enumerating through it</a></p>
  </blockquote>
  
  <p>I have a dictionary object which I iterate over and do some operations. Based on a condition, I should either delete or keep the key value pair I am currently iterating over. What is the best way to delete a key value pair from a dictionary while iterating over it? I tried to use a separate dictionary object to keep track of the elements to delete, but I'm not sure how to then use it to delete from my main dictionary or if that's even the most efficient way to do it.</p>