Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 连接两个Func委托_C#_Lambda_Concatenation_Func - Fatal编程技术网

C# 连接两个Func委托

C# 连接两个Func委托,c#,lambda,concatenation,func,C#,Lambda,Concatenation,Func,假设我有这个类: public class Order { int OrderId {get; set;} string CustomerName {get; set;} } 我还声明了以下变量 Func<Order, bool> predicate1 = t=>t.OrderId == 5 ; Func<Order, bool> predicate2 = t=>t.CustomerName == "Ali"; Func-predicate1=

假设我有这个类:

public class Order
{
   int OrderId {get; set;}
   string CustomerName {get; set;}
}
我还声明了以下变量

Func<Order, bool> predicate1 = t=>t.OrderId == 5 ;
Func<Order, bool> predicate2 = t=>t.CustomerName == "Ali";
Func-predicate1=t=>t.OrderId==5;
Func predicate2=t=>t.CustomerName==“Ali”;
是否有任何方法将这些变量(与和/或)连接起来,并将结果放入第三个变量中? 例如:

Func<Order, bool> predicate3 = predicate1 and predicate2;
Func-predicate3=谓词1和谓词2;

Func-predicate3=谓词1或谓词2;
和:

Func谓词3=
顺序=>predicate1(顺序)和predicate2(顺序);
或:

Func谓词3=
顺序=>谓词1(顺序)|谓词2(顺序);

这需要在搜索结果中排名靠前,因为所有排名靠前的答案都需要使用表达式类型。最佳答案,优雅!
Func<Order, bool> predicate3 = predicate1 or predicate2;
Func<Order, bool> predicate3 = 
    order => predicate1(order) && predicate2(order);
Func<Order, bool> predicate3 = 
    order => predicate1(order) || predicate2(order);