public static void Main(string[] args) { var searchParameters = new HorseSearch { YearWon = null, Horse = null, Jockey = null, Trainer = null, Owner = null, Page = 1, PageSize = 5 }; Console.WriteLine("Type any key to see a list of Derby Winners"); var horses = KentuckyDerbyWinners.LoadHorses(); while (Console.ReadKey().KeyChar != 'q') { Console.WriteLine($"Page: {searchParameters.Page}"); horses.Search(searchParameters).ToList().ForEach(s => { Console.WriteLine(s); }); searchParameters.Page++; } }
public static IEnumerable <Horses> Search(this IEnumerable <Horses> source, HorseSearch search) { return(source.Where(s => search.YearWon == null || s.YearWon.Contains(search.YearWon)) .Where(s => search.Horse == null || s.Horse.Contains(search.Horse)) .Where(s => search.Jockey == null || s.Jockey.Contains(search.Jockey)) .Where(s => search.Trainer == null || s.Trainer.Contains(search.Trainer)) .Where(s => search.Owner == null || s.Owner.Contains(search.Owner)) .Skip(search.Page * search.PageSize) .Take(search.PageSize)); }