Concatenating Lambda Functions in C#

前端 未结 6 1874
臣服心动
臣服心动 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:24

    The += is syntactic sugar specifically implemented to support adding handlers to events. Since events are just a special case of delegate, and Func is also a delegate, the syntax appears to work here.

    But are you sure it works as expected? By that I mean, do you expect an AND or OR evaluation? How would you implement the opposite if you wanted it? Are you sure it's not just returning the result of the first? Or the last?

提交回复
热议问题