1. 程式人生 > >匿名方法與Lamda表達式

匿名方法與Lamda表達式

con reading span ner ogr ask pro ole static

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 匿名方法與Lamda表達式
{
    class Program
    {
        static void Main(string[] args)
        {
            //任何可以使用委托的地方都可以使用匿名方法,匿名方法就是沒有名字的方法。
            //a指向一個匿名方法
            Action a = delegate
{ Console.WriteLine("a"); }; a(); //b指向一個lamda方法,labda方法可以訪問外部參數。 Action<string,string> b = (b1,b2) => { Console.WriteLine(b1+","+b2); }; b("b1","b2"); //當lamda只有一個參數和只有一句代碼時,參數可以不用(),方法體可以不能{} Action<string> c = d => Console.WriteLine(d); c(
"c"); Console.ReadKey(); } } }

匿名方法與Lamda表達式