Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate two Func delegates

I have this Class:

public class Order {    int OrderId {get; set;}    string CustomerName {get; set;} } 

I declare below variables, too

Func<Order, bool> predicate1 = t=>t.OrderId == 5 ; Func<Order, bool> predicate2 = t=>t.CustomerName == "Ali"; 

Is there any way that concatenate these variables(with AND/OR) and put the result in 3rd variable? for example:

Func<Order, bool> predicate3 = predicate1 and predicate2; 

or

Func<Order, bool> predicate3 = predicate1 or predicate2; 
like image 817
Masoud Avatar asked Jun 13 '13 13:06

Masoud


1 Answers

And:

Func<Order, bool> predicate3 =      order => predicate1(order) && predicate2(order); 

Or:

Func<Order, bool> predicate3 =      order => predicate1(order) || predicate2(order); 
like image 178
Steven Avatar answered Oct 22 '22 05:10

Steven