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?
Well, you could call the method that does exactly what you want.
Generally it is “better” to use the method that does exactly what you want rather than re-inventing it yourself.