/*
* 由SharpDevelop创建。
* 用户: David Huang
* 日期: 2015/7/30
* 时间: 16:32
*/
using System; namespace Lambda
{
class Program
{
public static void Main(string[] args)
{
//匿名委托
Func<int,int> Del0=delegate(int i)
{
return i*;
}; //进化了
Func<int,int> Del1= i=>
{
return i*;
}; //又进化了
Func<int,int> Del2 = i => i * ; //多个参数,多行,写法同Del1。参数类型要么都写,要么都不写
Func<int,int,int> Del3 = (int a, int b) =>
{
a++;
b++;
return a+b;
}; //
Func<int,int,int> Del4 = (a, b) => ++a + ++b; Console.WriteLine(Del0());
Console.WriteLine(Del1());
Console.WriteLine(Del2());
Console.WriteLine(Del3(,));
Console.WriteLine(Del4(,)); Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}

委托、 Lambda表达式和事件——Lambda表达式的更多相关文章

  1. C# 委托、lambda表达式和事件

    什么是委托?委托就是持有一个或多个方法的对象,并且该对象可以执行,可以传递. using System; using System.Collections.Generic; using System. ...

  2. 委托、Lambda表达式、事件系列07,使用EventHandler委托

    谈到事件注册,EventHandler是最常用的. EventHandler是一个委托,接收2个形参.sender是指事件的发起者,e代表事件参数. □ 使用EventHandler实现猜拳游戏 使用 ...

  3. 委托、Lambda表达式、事件系列06,使用Action实现观察者模式,体验委托和事件的区别

    在"实现观察者模式(Observer Pattern)的2种方式"中,曾经通过接口的方式.委托与事件的方式实现过观察者模式.本篇体验使用Action实现此模式,并从中体验委托与事件 ...

  4. 委托、Lambda表达式、事件系列05,Action委托与闭包

    来看使用Action委托的一个实例: static void Main(string[] args) { int i = 0; Action a = () => i++; a(); a(); C ...

  5. 委托、Lambda表达式、事件系列04,委托链是怎样形成的, 多播委托, 调用委托链方法,委托链异常处理

    委托是多播委托,我们可以通过"+="把多个方法赋给委托变量,这样就形成了一个委托链.本篇的话题包括:委托链是怎样形成的,如何调用委托链方法,以及委托链异常处理. □ 调用返回类型为 ...

  6. 委托、Lambda表达式、事件系列03,从委托到Lamda表达式

    在"委托.Lambda表达式.事件系列02,什么时候该用委托"一文中,使用委托让代码简洁了不少. namespace ConsoleApplication2 { internal ...

  7. 委托、Lambda表达式、事件系列02,什么时候该用委托

    假设要找出整型集合中小于5的数. static void Main(string[] args) { IEnumerable<int> source = new List<int&g ...

  8. 委托、Lambda表达式、事件系列01,委托是什么,委托的基本用法,委托的Method和Target属性

    委托是一个类. namespace ConsoleApplication1 { internal delegate void MyDelegate(int val); class Program { ...

  9. C#编程 委托 Lambda表达式和事件

    委托 如果我们要把方法当做参数来传递的话,就要用到委托.简单来说委托是一个类型,这个类型可以赋值一个方法的引用. 声明委托 在C#中使用一个类分两个阶段,首选定义这个类,告诉编译器这个类由什么字段和方 ...

随机推荐

  1. matlab在图片上画框

    matlab在图片上画框 之前写过一个MATLAB在图片上画框的代码, http://blog.csdn.net/carson2005/article/details/17262811 最近使用后发现 ...

  2. call和apply还有bind

    有图有真相 function myfun1(){ //这是私有属性 var private1 = "这是私有属性1"; var privateMethod = function() ...

  3. Ubuntu 12安装Virtualbox

    用aptitude或者apt-get安装Virtualbox,安装过程中会报:”No suitable module for running kernel found [fail]“,安装未成功. 在 ...

  4. Qt写的截图软件包含源代码和可执行程序

    http://blog.yundiantech.com/?log=blog&id=14 Qt写的截图软件包含源代码和可执行程序 http://download.csdn.net/downloa ...

  5. 【CF】220B Little Elephant and Array

    区间动态统计的好题. /* */ #include <iostream> #include <string> #include <map> #include < ...

  6. OpenWrt挂载USB储存设备实现Samba共享

    没有USB接口的路由器不是好路由器,有了USB接口OpenWrt才有更多的玩法,比如挂载U盘.移动硬盘等USB储存设备实现Samba共享,打造小型家庭服务器. 1.安装与USB相关的软件包: opkg ...

  7. [LeetCode#12] Roman to Integer

    Problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...

  8. poj1637

    混合图欧拉回路首先先明确基本概念连通的无向图存在欧拉回路当且仅当不存在奇点连通的有向图当且仅当每个点入度=出度这道题我们显然应该当作连通的有向图来做这个问题的困难之处在于我不知道应该从无向边的什么方向 ...

  9. Mysql慢日志查询

    MYSQL慢查询配置: 查看是否启用慢日志查询: show VARIABLES like '%quer%'; 没有配置的情况下慢查询是关闭的:

  10. 【JS】JS外联不执行,内联执行

    匹配域名http://lb.qq.com 或 http://lb.l.qq.com