Remove

public static void Remove<T>(this ICollection<T> list, Func<T, bool> predicate)
        {
            var items = list.Where(predicate).ToList();

            foreach (var item in items)
            {
                list.Remove(item);
            }
        }
Example:
var numbers = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

numbers.Remove(x => x > 5);

Description

Removes items from a list based on a condition you provide. I have a feeling this should exist already but I can't find it. You can get the same results using 'where' but this method operates on the collection itself.

Details

Double click on the code to select all.

 

;