Create filters without having a collection?
I think I may have a temporary mental glitch here, so excuse me if this is a stupid question, but I'm wondering if filters can be created so that they can be applied to a collection:
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4 };
Func<int, bool> filter = GetFilter();
IEnumerable<int> result = a.Where(filter);
}
private static Func<int, bool> GetFilter()
{
Func<int, bool> filter = c => c % 2 == 0;
// What if I wanted to further refine my filter here?
// For instance, add a ceiling of 10
return filter;
}
+3
source to share