Reputation: 1953
If I have a predicate expression returning method called GetPredicate
that I use for a list of users such as return u => u.age == 30
, is there a better way to check if a single item user1
satisfies this condition than doing this:
var validUser = (new List<User>(){ user1}).Where(GetPredicate()).SingleOrDefault();
Because this feels kind of hacky.
Upvotes: 0
Views: 32
Reputation: 13652
A predicate is just a delegate that can be invoked like a regular method:
var validUser = GetPredicate()(user1);
Upvotes: 1