static class Extensions
{
public static IEnumerable<TSource> Remove<TSource>(this IEnumerable<TSource> collection, Predicate<TSource> predicate)
{
foreach(TSource item in collection)
{
if(!predicate?.Invoke(item)) yield return item;
}
}
}
class Program
{
public static void Main()
{
IEnumerable<Shape> shapes = new List<Shape> { new Square(), new Triangle(), new Circle(), new Circle() };
foreach(var shape in shapes.Remove(t => t.GetType() == typeof(Circle)))
{
Console.WriteLine(shape.GetType()); // Square, Triangle
}
}
}