示例代码如下,控制台应用程序:

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

namespace LambdaExpressionDemo
{
    delegate void AddHandler(int a, int b);

    class Program
    {
        event AddHandler AddEvent;

        static void Main(string[] args)
        {
            int x = 10;
            int y = 5;
            Program program = new Program();

            program.AddEvent += new AddHandler(Program.program_AddEvent);

            program.AddEvent += delegate(int a, int b)
            {
                Console.WriteLine("C# 2.0时代的事件处理方式");
                Console.WriteLine(a + b);
            };

            program.AddEvent += (a, b) =>
            {
                Console.WriteLine("C# 3.0时代的事件处理方式");
                Console.WriteLine(a + b);
            };

            program.AddEvent(x, y);
        }

        static void program_AddEvent(int a, int b)
        {
            Console.WriteLine("C# 1.0时代的事件处理方式");
            Console.WriteLine( a + b );
        }
    }
}

尊重作者,转发请注明出处:http://www.cnblogs.com/aaaaa
谢谢阅读,有错请指出,不甚感激。

posted on 2012-09-25 17:17  163com  阅读(149)  评论(0编辑  收藏  举报