I am struggling to understand why does not List<T>FindAll(...)
method accepts Func<TSource, bool>
but instead insists on accepting Predicate<TSource>
.
So when I have a List
of books and I want to get only books, which are cheaper than 10. This code runs just fine.
Predicate<Book> CheapBooksPredicate = b => b.Price < 10;
var cheapBooksPredicate = books.FindAll(CheapBooksPredicate);
But when I change Predicate<TSource>
to Func<TSource, bool>
Func<Book, bool> CheapBooksFunc = b => b.Price < 10;
var cheapBooksFunc = books.FindAll(CheapBooksFunc);
I am getting error:
Argument 1: cannot convert from 'System.Func' to 'System.Predicate'
What Am I missing here ? When both Func<TSource, bool>
and Predicate<TSource>
are predicates
. Predicate<TSource>
should be specialized version of a Func
that takes and evaluates a value against a set of criteria and returns a boolean, thus I though, that they can replace each other in terms of usage.