Better way to remove matched items from a list

c#, list

Solution

Well, you could call the method that does exactly what you want.

myList.RemoveAll(IsMatching);

Generally it is "better" to use the method that does exactly what you want rather than re-inventing it yourself.

Problem

In c#, when I want to remove some items from a list, i do it in the following way, ``` List<Item> itemsToBeRemoved = new List<Item>(); foreach(Item item in myList) { if (IsMatching(item)) itemsToBeRemoved.Add(item); } foreach(Item item in itemsToBeRemoved) { myList.Remove(item); } ``` Is there any better way to do it?

Original source

Related problems