Removing multiple objects from a list according to some criteria
<p>I came across some code at one point that was trying to remove objects from a list that met a certain criteria.</p>

<p>There was a list of said objects that was already created with some stuff in it:</p>

<pre><code>List&lt;Foo&gt; FooList = new List&lt;Foo&gt;()
FooList.Add(...)
FooList.Add(...)
</code></pre>

<p>In some other function, they then went off to remove some objects:</p>

<pre><code>List&lt;Foo&gt; RemovedFoo = new List&lt;Foo&gt;()
foreach (Foo f in FooList
    if (f.Condition)
        RemoveFoo.Add(f);

foreach (Foo f in RemovedFoo)
    FooList.Remove(f);

RemovedFoo.Clear();
</code></pre>

<p>Is there a better way of doing this? I understand that you can't simply do the remove in the first loop, but surely there must be a smarter way to do this.</p>
