Possible Duplicate:
Modifying .NET Dictionary while Enumerating through it
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.