zoukankan      html  css  js  c++  java
  • C#Lambda表达式的用法

     

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

    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/minotmin
    谢谢阅读,有错请指出,不甚感激。

  • 相关阅读:
    ubuntu14.04 允许root用ssh登录
    MySQL(Navicat)运行.sql文件时报错:[Err] 2006
    Ubuntu14.04 安装git
    Ubuntu14.04下安装redis
    ubuntu apt-get update 失败解决
    检出商品详情中的图片并替换url
    nohup和&后台运行,进程查看及终止
    ubuntu 的chmod 和 chown
    php5.4安装fileinfo扩展
    crontab
  • 原文地址:https://www.cnblogs.com/minotmin/p/2701859.html
Copyright © 2011-2022 走看看