using System; using System.Collections.Generic; using System.Linq.Expressions; class Program { static void Main(string[] args) { Listnumbers = new List { 1, 2, 3, 4, 5}; Predicate greaterThanThree = n => n > 3; List filtered = numbers.FindAll(greaterThanThree); foreach (int number in filtered) { Console.WriteLine(number); } } }
4 5
using System; using System.Collections.Generic; using System.Linq.Expressions; class Program { static void Main(string[] args) { Listnames = new List { "Alice", "Bob", "Charlie", "David" }; Expression > lengthGreaterThanFive = name => name.Length > 5; List filtered = names.Where(lengthGreaterThanFive.Compile()).ToList(); foreach (string name in filtered) { Console.WriteLine(name); } } }
CharliePackage library: System.Core