Is there a way to create a consuming foreach
loop in C#?
basically loop through a Collection items and simultaneously consume them?
In plain English: Instead of just looping through the elements, remove the item from the collection, do stuff with it, then go to the next.
EDIT I neglected to mention that I am using a producing consuming pattern and this is why I wanted a consuming foreach. Most of the answers here are completely valid for the simple case I described before this edit, although what I wanted is described in my answer