using System.Collections.Generic;
public static void Main()
var shapes = new List<Shape> {
new Shape { ShapeType = ShapeType.Circle },
new Shape { ShapeType = ShapeType.Square },
new Shape { ShapeType = ShapeType.Triangle },
new Shape { ShapeType = ShapeType.Square },
new Shape { ShapeType = ShapeType.Hexagon }
Func<Shape, bool> predicate = isSquare;
IEnumerable<Shape> squares = filter (shapes, predicate);
foreach(var square in squares) Console.WriteLine(square);
public static bool isSquare(Shape item) => item.ShapeType == ShapeType.Square;
public ShapeType ShapeType;
public override string ToString(){
return $"I am a {ShapeType}.";
public static IEnumerable<T> filter<T>(IEnumerable<T> collection, Func<T, bool> predicate)
foreach (var element in collection)
public static IEnumerable<T> filter<T>(IEnumerable<T> collection, Predicate<T> predicate)
foreach (var element in collection)