/*
* 由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. Codeforces 713 C Sonya and Problem Wihtout a Legend

    Description Sonya was unable to think of a story for this problem, so here comes the formal descript ...

  2. prototype.js 源码解读(01)

    prototype.js是一个设计的非常优雅且很有实用价值的js基础类库,其源码非常值得研究.研究它的源码不仅能提升个人水平,而且对你打下坚实的js基础也很有帮助.因本人技术水平有限,该解读仅供参考. ...

  3. nodejs服务

    http://www.csser.com/board/4f55035305ee2e572400005e http://blog.fens.me/nodejs-server-forever/ http: ...

  4. 加快AndroidStudio运行速度的方法

    之前用过其他人加速AndroidStudio构建速度的方法,确实在编译时有一定的效果 但是在实际使用中,随着项目越来越大,AndroidStudio有时还是会卡死,或者直接黑屏,我的笔记本是8g内存 ...

  5. css li 列表

    ul,li{list-style-type:none;padding:0;margin:0}

  6. 【CF】220B Little Elephant and Array

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

  7. 【HDOJ】1421 搬寝室

    DP.这题都能TLE,发现memset有时居然比for还要慢. #include <stdio.h> #include <stdlib.h> #include <stri ...

  8. Android adb opendir failed ,permission denied

    最近在使用adb命令ls的时候会提示:adb opendir failed ,permission denied , 解决方法: adb shell cd data/data/pakageName l ...

  9. unity3d shader之Roberts,Sobel,Canny 三种边缘检测方法

    方法其实都差不多,就是用两个过滤器,分别处理两个分量 Sobel算子 先说Sobel算子 GX为水平过滤器,GY为垂直过滤器,垂直过滤器就是水平过滤器旋转90度.过滤器为3x3的矩阵,将与图像作平面卷 ...

  10. 用redis实现支持优先级的消息队列

    http://www.cnblogs.com/tianqiq/p/4309791.html http://www.cnblogs.com/it-cen/p/4312098.html http://ww ...