作为一个初学者,写下来是当做自己的学习笔记,希望在以后遇到问题的时候能够快速的找到方法

如果能帮助跟我一样的新人是更好不过的了        如果有什么不正确或者可以改进的地方也希望大家能够指出来  谢谢大家

1.委托

来百度一下什么是委托:委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递,这种将方法动态地赋给参数的做法,可以避免在程序中大量使用If-Else(Switch)语句,同时使得程序具有更好的可扩展性。(百度百科)

先来写个简单的委托:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication2
{
class Program
{
//声明没有参数,没有返回值的委托
public delegate void MyDelegate();
//委托对象
static MyDelegate myDelegate; public static void Show()
{
Console.WriteLine("我的代理");
} static void Main(string[] args)
{
myDelegate = new MyDelegate(Show);//实例化委托 委托myDelegate去做Show的事情
myDelegate();//调用myDelegate
Console.ReadKey();
}
}
}

将上面的改为带参数,带返回值的委托

class Program
{
//声明带参数,带返回值的委托
public delegate string MyDelegate(string data);
//委托对象
static MyDelegate myDelegate; public static string Show(string data)
{
return data;
} static void Main(string[] args)
{
myDelegate = new MyDelegate(Show);//实例化委托 委托myDelegate去做Show的事情
Console.WriteLine(myDelegate("委托的参数"));//在调用时,需要带上参数
Console.ReadKey();
}
}

现在我们写两个方法

 class Program
{
//声明带参数,带返回值的委托
public delegate void MyDelegate();
//委托对象
static MyDelegate myDelegate; public static void ShowOne()
{
Console.WriteLine("委托一号");
} public static void ShowTwo()
{
Console.WriteLine("委托二号");
}
}

我们现在想输出两个中的一个  可以改成这样  顺便复习一下带参数的委托

class Program
{
//声明带参数的委托
public delegate void MyDelegate(string data);
//委托对象
static MyDelegate myDelegate; public static void Show(string data)
{
switch (data)
{
case "委托一号":
Console.WriteLine("委托一号");
break;
case "委托二号":
Console.WriteLine("委托二号");
break;
}
} static void Main(string[] args)
{
myDelegate = new MyDelegate(Show);
myDelegate("委托一号");//调用时的参数是什么就会输出对应的委托了
Console.ReadKey();
}
}

什么委托一号  什么委托二号 这个好记 要是选项多了  东西又不太好记怎么办  稍微改进一下

/// <summary>
/// 1是委托一号 2是委托二号
/// </summary>
   enum DATA
{
zero,
NumOne,
NumTwo,
}; class Program
{
//声明带参数的委托
public delegate void MyDelegate(DATA data);
//委托对象
static MyDelegate myDelegate; public static void Show(DATA data)
{
switch (data)
{
case DATA.NumOne:
Console.WriteLine("委托一号");
break;
case DATA.NumTwo:
Console.WriteLine("委托二号");
break;
}
} static void Main(string[] args)
{
myDelegate = new MyDelegate(Show);
myDelegate(DATA.NumTwo);
Console.ReadKey();
}
}

是不是瞬间感觉高大上了     还有要活用/// <summary>    /// </summary>      这可是好东西 可以让别人用你代码的时候更加的清楚用的是什么有什么用处     可以提高代码的可读性哦

2.事件

如果我们希望两个方法同时输出该怎么做呢    应该这样:

 class Program
{
//声明带参数,带返回值的委托
public delegate void MyDelegate();
//委托对象
static event MyDelegate myDelegate;//此处与上面不同哦 public static void ShowOne()
{
Console.WriteLine("委托一号");
} public static void ShowTwo()
{
Console.WriteLine("委托二号");
} static void Main(string[] args)
{
myDelegate = new MyDelegate(ShowOne);//先给你对象赋上一个方法
myDelegate += new MyDelegate(ShowTwo);//再给你加上一个方法
myDelegate();//调用
Console.ReadKey();
}
}

看下输出  调用一个  两个同时都显示出来了  没错这就是事件(event)

事件可以加 那能不能减呢   聪明  你没有猜错 当然可以  改完后看下结果

 static void Main(string[] args)
{
myDelegate = new MyDelegate(ShowOne);//先给你对象赋上一个方法
myDelegate += new MyDelegate(ShowTwo);//再给你加上一个方法
myDelegate();//调用
Console.WriteLine("__________________________我来分割________________________");
myDelegate -= new MyDelegate(ShowOne);
myDelegate();//减完后再调一次
Console.ReadKey();
}

3.匿名方法

委托和事件说完了  来看看特别一点的    匿名方法

在之前  每次实例化委托的时候都要有一个已经写好的方法  而匿名方法则不需要

    class Program
{
//声明带参数的委托
public delegate void MyDelegate(string data);
//委托对象
static MyDelegate myDelegate; static void Main(string[] args)
{
myDelegate = delegate(string data) //带参数
{
Console.WriteLine(data);
};
myDelegate("带参数的匿名方法");
Console.ReadKey();
}
}

不带参数的只要将参数去掉即可       delegate后面跟上你需要用的参数在{}中进行你需要的操作  最后不要忘记带上分号哦

4.Lambda表达式

要是匿名方法还不够快  那试试这个

class Program
{
//声明带参数的委托
public delegate void MyDelegate(string data);
//委托对象
static MyDelegate myDelegate; static void Main(string[] args)
{
myDelegate = (string data) => { Console.WriteLine(data); };
myDelegate("带参数Lambda表达式");
Console.ReadKey();
}
}

代码量是不是更少了呢  直接用小括号写上参数,然后是=> 再用个{}来框住你的操作  同样最后也有分号

5.Action

先来看看它的解释

参数可以有好多也可以没有  但是  他没有返回值  来看看怎么用吧

class Program
{
//不带参数的Action
static Action actionOne;
//带参数的Action
static Action<string> actionTwo; static void Main(string[] args)
{
actionOne = new Action(ShowOne);
actionOne(); actionTwo = new Action<string>(ShowTwo);
actionTwo("Action ShowTwo");
Console.ReadKey();
} static void ShowOne()
{
Console.WriteLine("Action ShowOne\n");
} static void ShowTwo(string data)
{
Console.WriteLine(data);
}
}

试着输出一下吧

6.Func

它与Action类似  但是他是必须带返回值的

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAt4AAADKCAIAAAAdLtCsAAAVg0lEQVR4nO3dPbLjuBUG0N5B74Cx1+LA4cyKvItx6tjBbMIb6KgX46DLKg4BXFyQoATpnVNdXXoUCIA/Ir4HSnrffvvjx7Zt27b99seP8t+v5Y9nDyW3/zusEiwsG2rV2VpY+rlTPpUv2Sp8KPD4v6wEALjo231VdyPF3UQHAHg7d0WT5ITHTVpTIwDA4m6cNQEAGCWaAAALEU0AgIWIJgDAQkQTAGAhogkAsBDRBABYiGgCACxENAEAFiKaAAALEU0AgIWIJgDAQkQTAGAhogkAsBDRBABYiGgCACxENAEAFiKaAAALEU0AgIUsFE1+//ffgx8BgK9gfjSpRopMzvhV5vd//738ty8T/5u4IQDA802OJqdzyb7YIYvE5cURAPgkS0STctojiB2mTADgg82MJlemTLbcDZ2tmFypzrUAAG9q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V6iC3bDpQfE9gmaTPmiAKKVF0WMwNhEN20zY3M5/elVM6uFWRbvkiMBN8ZS4TrsMNCkGrOcrG1b3dT84xtuWGNfd9aqFXiXzIJQb8OudiPxMGENSKStqWq11uRWkp7pfbX0am8h4OZ/pkOvxWjlTRBGbrE8u9Ndu0f5QAbgHgAYBNKqbn+eKb6cz80ecN+rA7XabPpK8G8C/o4xt3EmyNp3fwbF7h1AlKF237XOplhCdqlVF0PLtTWuVdRTcX2bmt7nAbfYXgZtNywQu4v2pM7GR8n3SYjFLQZwDwAAALBpgHsAAACATQPcAwAAAGwa4B4AAABg0wD3AAAAAJvG+eeek5PTGzde2npHAwAAAB2Oj2+ef+45Ohq9+OJ3jo9vbr27AQAAgOPjm9/+9vXx+LtZ673f3PPEE3/60kt/fXr6CgAAALALGI+/+/Wv/1nWeu8390AgEAhkHwXcA4FAIJBNy/8D8tCOhgvhgowAAAAASUVORK5CYII=" alt="" />

前面的都是它的参数, 最后一个参数就是他的返回值

 //不带参数的Action
static Func<string> FuncOne;
//带参数的Action
static Func<string,string> FuncTwo; static void Main(string[] args)
{
FuncOne = new Func<string>(ShowOne);
Console.WriteLine(FuncOne()); FuncTwo = new Func<string, string>(ShowTwo);
Console.WriteLine(FuncTwo("Func ShowTwo"));
Console.ReadKey();
} static string ShowOne()
{
return "Func ShowOne\n";
} static string ShowTwo(string data)
{
return data;
}

大家试着自己输出吧  毕竟程序还是要多练的哦

C#委托,事件,匿名委托的更多相关文章

  1. Unity C# 多态 委托 事件 匿名委托 Lambda表达式 观察者模式 .NET 框架中的委托和事件

    一.多态 里氏替换原则: 任何能用基类的地方,可以用子类代替,反过来不行.子类能够在基类的基础上增加新的行为.面向对象设计的基本原则之一. 开放封闭原则: 对扩展开放,意味着有新的需求或变化时,可以对 ...

  2. 委托、匿名委托、Lambda 表达式、Expression表达式树之刨根问底

    本篇不是对标题所述之概念的入门文章,重点在阐述它们的异同点和应用场景.各位看官,这里就不啰嗦了,直接上代码. 首先定义一个泛型委托类型,如下: public delegate T Function&l ...

  3. 帮助理解委托、匿名委托、Lambda表达式还有事件

    写了一个小程序,能够很好的认识到这三个的用法 namespace Lambda { /// <summary> /// 实现根据指定运算形式 输出结果 /// </summary&g ...

  4. C#基础精华07(委托事件,委托的使用,匿名方法)

    1.委托概述 委托是一种数据类型,像类一样(可以声明委托类型变量).方法参数可以是int.string.类类型 void M1(int n){  } √ void M2(string s){  } √ ...

  5. 委托、匿名委托和lambda表达式

    1.委托 在.NET中,委托有点类似于C/C++中的函数指针,但与指针不同的是,委托是一种安全的类型,那么我们就以实现两个数的差为例,先声明一个成员方法: public int CompareTwoV ...

  6. linq和匿名方法、委托、匿名委托、lambda

    委托相当于JavaScript中的闭包,c++中的函数指针. c#为了引进这个函数指针,将其进行包装成“委托”,同时将非托管的变成托管的. 1.最初的委托该怎么用 弊端:写的代码量过多,还要写一个显示 ...

  7. C#,委托,匿名委托,Lambda表达式

    1. 委托是什么? (1) 从数据结构来讲,委托是和类一样是一种用户自定义类型.  (2) 从设计模式来讲,委托(类)提供了方法(对象)的抽象.概括的说:委托是方法的抽象. 2. 委托类型的定义: 委 ...

  8. C# ~ 从 委托事件 到 观察者模式 - Observer

    委托和事件的部分基础知识可参见 C#/.NET 基础学习 之 [委托-事件] 部分: 参考 [1]. 初识事件 到 自定义事件: [2]. 从类型不安全的委托 到 类型安全的事件: [3]. 函数指针 ...

  9. 匿名委托与Lambda表达式

    通过使用匿名委托(匿名方法),使编程变得更加灵活,有关委托与匿名委托请参考我的前一篇Blog<委托与匿名委托>. 继续之前示例,代码如下: static void Main(string[ ...

  10. .net 系列:Expression表达式树、lambda、匿名委托 的使用

    首先定义一个泛型委托类型,如下: public delegate T Function<T>(T a, T b); 实现泛型委托的主体代码,并调用: public static strin ...

随机推荐

  1. C#基础:委托 【转】

    委托是C#中最为常见的内容.与类.枚举.结构.接口一样,委托也是一种类型.类是对象的抽象,而委托则可以看成是函数的抽象.一个委托代表了具有相同参数列表和返回值的所有函数.比如: delegate in ...

  2. 项目总结——SqlParameter的参数设置长度(size属性)

    看到很多朋友在实例化SqlParameter时,通常都没有指定参数的长度就直接给参数赋值了.就像下面的写法: new SqlParameter("@address", SqlDbT ...

  3. 绿色mysql启动脚本

    启动脚本如下:./mysqld_safe --defaults-file=/export/servers/mysql-5.5.38/my.cnf --ledir=/export/servers/mys ...

  4. 使用sumlime text有感

    学习JS和CSS.HTML用sublime text挺好的,这个工具不仅打开速度很快,而且也容易让页面运行(右键,在浏览器中打开),新建html页面的时候,先写个感叹号,然后按ctrl+e,会自动生成 ...

  5. oracle中set define off

    set define off关闭替代变量功能 在SQL*Plus中默认的"&"表示替代变量,也就是说,只要在命令中出现该符号,SQL*Plus就会要你输入替代值.这就意味着 ...

  6. Hql参数占位符使用(转+整理)

    在Hibernate 4版本中,对于Hql有一点点改变,如果你还是按照以前的方式去编写HQL Query query = sessionFactory.openSession().createQuer ...

  7. Java面试题整理(题目内容非原创)

    面试题分类: 1.java 基础面试题 Java基础中对于io 中文件的读.写,util中的list map set这些要分清楚 还有线程.socket 都需要了解下 参考链接:http://blog ...

  8. C++#define的用法(含特殊)

    1 无参宏定义无参宏的宏名后不带参数.其定义的一般形式为:    #define 标识符 字符串其中的“#”表示这是一条预处理命令.凡是以“#”开头的均为预处理命令.“define”为宏定义命令.“标 ...

  9. [jQuery] jQuery如何获取同一个类标签的所有的值

    碰巧在开发的时候遇到这个问题,因为jQuery总是只返回第一个类标签的值,所以无法达到我们的要求. 比如: var btn = jQuery('.btn').val(); 获取的只是第一个类标签为bt ...

  10. Android 自定义下拉刷新ListView

    package com.dwtedx.qq.view; import android.content.Context; import android.util.AttributeSet; import ...