RemoveAll()

using System;
using System.Collections.Generic;
using System.Linq;

public static class CollectionExtensions
{
    public static void RemoveAll<T>(this ICollection<T> @this, Func<T, bool> predicate)
    {
        List<T> list = @this as List<T>;

        if (list != null)
        {
            list.RemoveAll(new Predicate<T>(predicate));
        }
        else
        {
            List<T> itemsToDelete = @this
                .Where(predicate)
                .ToList();

            foreach (var item in itemsToDelete)
            {
                @this.Remove(item);
            }
        }
    }
}
Example:
ICollection<int> items = new List<int>(new[] { 1, 3, 5 });
items.RemoveAll(x => x > 2);

ICollection<int> linkedItems = new LinkedList<int>(new[] { 1, 3, 5 });
linkedItems.RemoveAll(x => x > 2);

Description

ICollection interface has List type most of time, so this Extension allows to call RemoveAll() method with the same signature like on List

Details

Double click on the code to select all.