匿名函数(委托)

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

namespace gc
{
    class Program
    {
        delegate void TestDelegate(string s);

        static void M(string s) {
            Console.WriteLine(s);
        }

        static void Main(string[] args)
        {
            //匿名函数
            TestDelegate TestDelA = new TestDelegate(M);//委托  "关联"
            TestDelegate TestDelB = delegate(string s) { Console.WriteLine(s); };//委托
            TestDelegate TestDelC = (x) => { Console.WriteLine(x); };//Lambda表达式

            TestDelA("我是委托A");
            TestDelB("我是委托B");
            TestDelC("我是委托C");

            Console.ReadKey();
        }
    }
}

posted @ 2012-11-25 10:01  FiberHomer  阅读(186)  评论(0编辑  收藏  举报