I’m working on a Silverlight 2/3 application. I would like to use List.RemoveAll (or maybe it’s IList.RemoveAll?) and specify a predicate so that I can remove a bunch of elements from a list in one sweep.
It seems like this function doesn’t exist in Silverlight, though. Am I missing something here? Is there an alternative approach that’s equally easy? Right now, I’m manually iterating over my elements in a foreach and keeping a second list (because you can’t delete while iterating), and it’s quite … cumbersome.
If what you really need is access to the subset, then there’s really no reason to do the remove, just access the subset like this:
Instead of (potentially:
Just get the inverse:
OK but to really remove them (assuming the same starting list as above):
.Where is an extension method on IEnumerable, in System.Linq.
So as long as your list is a generic IEnumerable (and you’ve added the using) it should be available.