What is the difference between a lambda expression

2019-03-18 02:02发布

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

2条回答
Luminary・发光体
2楼-- · 2019-03-18 02:22

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-03-18 02:45

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;
查看更多
登录 后发表回答