What is the best way to remove a set from a collection, but still keep the items that were removed in a separate collection?
I have written an extension method that
I don't agree that it is the most efficient - you are calling the predicate match twice on each element of the list.
I'd do it like this:
var ret = new List();
var remaining = new List();
foreach (T t in lst) {
if (match(t))
{
ret.Add(t);
}
else
{
remaining.Add(t);
}
}
lst.Clear();
lst.AddRange(remaining);
return ret;