日期:2014-05-20  浏览次数:20789 次

用辣妹答表达式有什么好处?回复均有分。。。
lambda表达式,

(int x, string s) => s.Length > x
------解决方案--------------------
短小精悍
------解决方案--------------------
你看看msdn中对lambda表达式的解释,其实就够了
------解决方案--------------------
引用:
短小精悍

其实我也想这么说的。 减少代码量 我觉得还是蛮好的。
------解决方案--------------------
原来for/foreach做的循环现在用find findall




------解决方案--------------------
好东西啊,简练得当!
------解决方案--------------------
原来lambda昵称辣妹表达式~
------解决方案--------------------
辣妹很辣
------解决方案--------------------
个人感觉  就好比   js 与 Jquery  一样的,还是辣妹好呗。/ 
------解决方案--------------------
短小精悍

------解决方案--------------------
我想说引用:
lambda表达式可以写匿名函数,然后可以访问函数外的局部变量,很好用

------解决方案--------------------
用起来简单一些哈。。
------解决方案--------------------
Lambda表达式(Lambda Expressions)2009-03-06 16:33Lambda 表达式(拉姆达表达式) 和 匿名方法 其实是一件事情。唯一的不同是:他们语法表现形式不同。Lambda 表达式是在语法方面的更进一步的进化。在本质上,他们是一件事情。他们的作用都是:产生方法。即:内联方法。

引用自 C#首席架构师Anders Hejlsberg 的原话:

http://www.ondotnet.com/pub/a/dotnet/2005/10/31/interview-with-anders-hejlsberg-part-2.html?page=2

lambda expressions and anonymous methods are really just two words for the same thing. The only thing that differs is, "What does the syntax look like?" And the lambda expressions are a further evolution of the syntax.But underneath, they do the same thing. They generate methods. You know, they're in-line methods.

所以:我们要了解 Lambda 表达式 就应该同时也了解 匿名方法。下面先看一个简单的代码例子,分别用匿名方法和Lambda 表达式来实现对数组的搜索:


使用 .net 2.0 的匿名方法来搜索字符串数组中包含 a 的字符串数组

static void Main(string[] args)
{
    string[] list = new string[] { "abc", "12", "java" };
    string[] ll = Array.FindAll(list,
        delegate(string s)
        {
            return s.IndexOf("a") >= 0;
        }
        );
    foreach (string var in ll)
    {
        Console.WriteLine(var);
    }
    Console.ReadLine();
}

使用 .net 3.5 的Lambda表达式来搜索字符串数组中包含 a 的字符串数组

static void Main(string[] args)
{
    string[] list = new string[] { "abc", "12", "java" };