你的位置:首页 > 软件开发 > ASP.net > C#之 Lambda表达式

C#之 Lambda表达式

发布时间:2016-06-13 16:00:14
Lambda表达式 简化了匿名委托的使用,让你让代码更加简洁,优雅。据说它是微软自c#1.0后新增的最重要的功能之一。首先来看一下其发展    根据上面的发展历程,可以感到Lambda表达式愈加简化。详细介绍:   using System;using System.Co ...

Lambda表达式 简化了匿名委托的使用,让你让代码更加简洁,优雅。据说它是微软自c#1.0后新增的最重要的功能之一。

首先来看一下其发展

  C#之 Lambda表达式

  根据上面的发展历程,可以感到Lambda表达式愈加简化。

详细介绍:

  C#之 Lambda表达式

C#之 Lambda表达式

 

C#之 Lambda表达式

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Lambda{  class Program  {    static void Main(get='_blank'>string[] args)    {      int sum = 0;      Func<int, int> f1 = x => 2 * x + 1;      Func<int, int, bool> f2 = (x, y) => x > y;      Func<string, int, string> f3 = (x, y) => x.Substring(y);      Func<int, int> f4 = (x) => sum += x;      Action a1 = () => { System.Console.WriteLine("HelloWorld"); };      Action <int> a2 = (x) => { System.Console.WriteLine(x); };      Action <bool> a3 = (x) => { System.Console.WriteLine(x); };      Action<string> a4 = (x) => { System.Console.WriteLine(x); };      for (int i = 1; i <= 10; i++ )      {        f4(i);      }      a2(sum);      a1();      a2(f1(1));      a3(f2(3, 5));      a4(f3("Zhengpengfei", 5));      System.Console.Read();    }  }}

原标题:C#之 Lambda表达式

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录