blogs

miércoles, 8 de julio de 2015

Lambda Expression


Lambda expression

it is an anonymous function that we can use to create a delegate type or tree expression
Instead of create a method, we give it a name and pass the name of this method to  the definition a delegate, we can use lambda expression to put code directly without create a method,give it the name and assign it to a delegate

Syntax 

(parameters the input)=>expression
(parameters the input)=>{sentence};


Assign a lambda expression to a delegate




Lambda expression as an argument type<Func>

Func, represent method that can return something value, for example: Define a delegate for methods that receive  one parameters and return a  type
Func<int, bool> define a delegate with input parameters and return type .
in the example the input is a int and return type is bool



When we invoke, return true or false to point if the  parameter of input is equal a 5




For Example:


Test result

For Examples

Lambda expression to count  odd numbers that has a array 
we need the library "System.LINQ".


Test result





No hay comentarios:

Publicar un comentario