Skip to content

Instantly share code, notes, and snippets.

@ferventcoder
Created September 24, 2012 22:29
Show Gist options
  • Save ferventcoder/3778846 to your computer and use it in GitHub Desktop.
Save ferventcoder/3778846 to your computer and use it in GitHub Desktop.
How to Remove Items from A List ?
foreach (var item in items.ToList())
{
items.Remove(item);
}
@ferventcoder
Copy link
Author

This does have an incurrence that you are making a copy of the object, but the code is very readable.

@ferventcoder
Copy link
Author

perhaps a much faster way of doing this: http://pastie.org/4792699

@vongillern
Copy link

as we discussed on twitter, this has potential worst case runtime of O(n*m) = O(n^2) instead of the pastie that has a worst case runtime of O(2n) = O(n) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment