What is the difference between a lambda expression

2019-03-18 01:44发布

问题:

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