zoukankan      html  css  js  c++  java
  • 委托、 Lambda表达式和事件——Lambda表达式

     1 /*
     2  * 由SharpDevelop创建。
     3  * 用户: David Huang
     4  * 日期: 2015/7/30
     5  * 时间: 16:32
     6  */
     7 using System;
     8 
     9 namespace Lambda
    10 {
    11     class Program
    12     {
    13         public static void Main(string[] args)
    14         {
    15             //匿名委托
    16             Func<int,int> Del0=delegate(int i)
    17             {
    18                 return i*2;
    19             };
    20             
    21             //进化了
    22             Func<int,int> Del1= i=>
    23             {
    24                 return i*2;
    25             };
    26             
    27             //又进化了
    28             Func<int,int> Del2 = i => i * 2;
    29               
    30             //多个参数,多行,写法同Del1。参数类型要么都写,要么都不写
    31             Func<int,int,int> Del3 = (int a, int b) =>
    32             {
    33                 a++;
    34                 b++;
    35                 return a+b;
    36             };
    37             
    38             //
    39             Func<int,int,int> Del4 = (a, b) => ++a + ++b;
    40             
    41             
    42             Console.WriteLine(Del0(2));
    43             Console.WriteLine(Del1(2));
    44             Console.WriteLine(Del2(2));
    45             Console.WriteLine(Del3(1,2));
    46             Console.WriteLine(Del4(1,2));
    47             
    48             
    49             Console.Write("Press any key to continue . . . ");
    50             Console.ReadKey(true);
    51         }
    52     }
    53 }
  • 相关阅读:
    POJ -- 3468
    HDOJ--1698
    简单的API应用
    Linux引导流程
    Python 实现网络爬虫小程序
    codeforce
    Count the string -- HDOJ 3336
    初次运行 Git 前的配置
    leetcode244- Shortest Word Distance II- medium
    leetcode243- Shortest Word Distance- easy
  • 原文地址:https://www.cnblogs.com/David-Huang/p/4689825.html
Copyright © 2011-2022 走看看