fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Program
  6. {
  7. public class Foo
  8. {
  9. public string data { get; set; }
  10. }
  11.  
  12. public class Bar : Foo
  13. {
  14. }
  15.  
  16. static void Main(string[] args)
  17. {
  18. var bars = new List<Bar>();
  19.  
  20. bars.Add(new Bar() { data = "hello" });
  21. bars.Add(new Bar() { data = "world" });
  22.  
  23. var resultsA = GetFoos(bars, (b => b.data.StartsWith("h")));
  24. var resultsB = GetBars(bars, (b => b.data.StartsWith("h")));
  25. }
  26.  
  27. static List<Foo> GetFoos(IEnumerable<Foo> fooList, Func<Foo, bool> criteria)
  28. {
  29. return fooList.Where(criteria).ToList();
  30. }
  31.  
  32. static List<Bar> GetBars(IEnumerable<Bar> barList, Func<Bar, bool> criteria)
  33. {
  34. return barList.Where(criteria).ToList();
  35. }
  36. }
Success #stdin #stdout 0.05s 24496KB
stdin
Standard input is empty
stdout
Standard output is empty