Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FilterTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- var words = new[] {"apple", "cat", "banana"};
- var filters = new List<Func<string, bool>>();
- filters.Add(WordContainsA);
- filters.Add(WordWordHasAtLeast5Letters);
- var result = words.Where(word => filters.All(filter => filter(word)));
- foreach (var word in result)
- {
- Console.WriteLine(word);
- }
- Console.ReadLine();
- }
- public static bool WordContainsA(string word)
- {
- return word.Contains("a");
- }
- public static bool WordWordHasAtLeast5Letters(string word)
- {
- return word.Length >= 5;
- }
- public static bool WordEndsWithA(string word)
- {
- return word.EndsWith("a");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment