Nikhil Agrawal Nikhil Agrawal - 2 months ago 14
C# Question

Combining Predicates in post .Net 2.0

What is the way of combining predicates like we used do for


I have a predicate

Predicate<Foo> predicate = p1 => (p1.IsActive) && p1.Type != "BR";


Predicate<Foo> datePredicate = p1 => (p1.Year) == DateTime.Now.Year;

Based on some condition I want to combine both so that resultant predicate can be passed to a method which accepts single predicate parameter.

predicate = predicate.????(datePredicate);

so what is the way to do it?


You can combine predicates as below

Predicate<Foo> datePredicateAnd = p =>(predicate(p) && datePredicate(p));