Skip to content

Instantly share code, notes, and snippets.

@kmorcinek
Created August 28, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmorcinek/4b2bebde7be759a6805e5c3de8da43ff to your computer and use it in GitHub Desktop.
Save kmorcinek/4b2bebde7be759a6805e5c3de8da43ff to your computer and use it in GitHub Desktop.
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);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment