Nikhil Agrawal
Nikhil Agrawal

Reputation: 48580

Combining Predicates in post .Net 2.0

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

I have a predicate

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

and

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?

Upvotes: 0

Views: 113

Answers (1)

Damith
Damith

Reputation: 63105

You can combine predicates as below

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

Upvotes: 1

Related Questions