Use of predicate and lambda expression

7

I am studying WPF and the MVVM template by the following article: link

In the implementation of the ICommand interface, the author defines the following field:

Predicate<object> _canExecute;               

When the class is instantiated, the following parameter is passed to this field:

x => canExecute

My question is, why is the parameter passed in the form of lambda expression?

    
asked by anonymous 20.05.2016 / 23:55

1 answer

2

Lambda expressions are very useful for creating queries with LINQ in Visual C #, and are nothing more than anonymous functions that you can use to create delegates and write local functions that can be passed as arguments or returned as values in calls from other functions.

A predicate on the other hand is a delegate that returns a boolean (0 or 1, V or F, true or false, yes or no, yes or no).

In this way, you can evaluate that the use of a lambda expression, given the context, is done because a predicate is expected to return a Boolean value, but this is a function object, which is typical of a delegate, and can therefore be passed as a parameter after being evaluated even though it is a function, which is typical of lambda functions or expressions.

    
21.05.2016 / 03:55