Concatenating Lambda Functions in C#

前端 未结 6 1961
臣服心动
臣服心动 2020-12-23 14:46

Using C# 3.5 I wanted to build up a predicate to send to a where clause piece by piece. I have created a very simple Console Application to illustrate the solution that I a

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 15:13

    Expanding on BFree's answer (+1'd it)

    If you want to get the behavior you're looking for, you'll need to explicitly chain the predicates together. Here is an example

    public static Func GetPredicate()
    {
        Func predicate1 = t => t.Response == "00";
        Func predicate2 = t => t.Amount < 100;
        return t => predicate1(t) && predicate2(t);
    }
    

提交回复
热议问题