This is how I remove an item from a List. Is this the right way? Is there any cleaner/faster way to achieve this.
List<ItemClass> itemsToErase = new List<ItemClass>();
foreach(ItemClass itm in DS)
{
if(itm.ToBeRemoved)
itemsToErase .Add(itm);
}
foreach(ItemClass eraseItem in itemsToErase)
{
DS.Remove(eraseItem );
}
EDIT: DS is of type List<ItemClass>
EDIT: Have one more doubt. What if DS is a LinkedList<ItemClass>. There is no RemoveAll() for that.
There is List.RemoveAll() which takes a delegate where you can add your comparison function.
E.g.: