LAMBDA解释和它是什么,以及一个很好的例子 [英] Lambda Explanation and what it is as well as a good example

查看:154
本文介绍了LAMBDA解释和它是什么,以及一个很好的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我如何使用LAMBDA一个很好的解释,并给出一个很好的例子。我已经看到了,但我不知道它是什么或做。

Can anyone give me a good explanation of how to use Lambda and give a good example. I have seen it but I dont know what it is or does.

推荐答案

一个拉姆达EX pression用来创建一个匿名函数。在这里,一个匿名函数被分配给一个委托变量:

A lambda expression is used to create an anonymous function. Here an anonymous function is assigned to a delegate variable:

Func<int, int> increase = (a => a + 1);

您可以再使用委托调用的函数:

You can then use the delegate to call the function:

var answer = increase(41);

通常拉姆达EX pressions用于发送一个委托的方法,例如派遣代表到的ForEach 方法,以便它呼吁每个元素清单:

Usually lambda expressions are used to send a delegate to a method, for example sending a delegate to the ForEach method so that it's called for each element in the list:

List<int> list = new List<int>();
list.Add(1);
list.Add(2);

list.ForEach(n => Console.WriteLine(n));

这篇关于LAMBDA解释和它是什么,以及一个很好的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆