What is the difference between a lambda expression and a predicate in .NET?

后端 未结 2 877
醉话见心
醉话见心 2021-02-07 09:51

What is the difference between a lambda expression and a predicate in .NET?

2条回答
  •  执笔经年
    2021-02-07 10:07

    A predicate is delegate (function object) that returns a boolean value. Lambda expressions can be used to define any anonymous function, which includes predicates, e.g. to express a predicate in the form of a lambda expression:

    Predicate isEven2 = x => x % 2 == 0;
    

    which is functionally equivalent to:

    Func isEven = x => x % 2 == 0;
    

提交回复
热议问题