Created
September 24, 2012 22:29
-
-
Save ferventcoder/3778846 to your computer and use it in GitHub Desktop.
How to Remove Items from A List ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (var item in items.ToList()) | |
{ | |
items.Remove(item); | |
} |
perhaps a much faster way of doing this: http://pastie.org/4792699
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
This does have an incurrence that you are making a copy of the object, but the code is very readable.