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

ぐ巨炮叔叔 提交于 2019-12-21 03:30:57

问题


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


回答1:


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<int> isEven2 = x => x % 2 == 0;

which is functionally equivalent to:

Func<int,bool> isEven = x => x % 2 == 0;



回答2:


Predicate defines a set of criteria, while lambda expression is an anonymous function. You can use lambda ex. as a predicate, but that doesn't mean they are the same thing.

Predicate

Lambda expression



来源:https://stackoverflow.com/questions/11286775/what-is-the-difference-between-a-lambda-expression-and-a-predicate-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!