c#的委托(3)之多重委托
来源:互联网 发布:淘宝买万艾可怎么购买 编辑:程序博客网 时间:2024/05/01 07:13
1.执行顺序是从头到尾依次执行的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Delegate
{
//multi-casting delegate
delegate void D(int x);
class Program
{
static void Main(string[] args)
{
D cd1 = new D(C.M1);
cd1(-1);
Console.WriteLine();
D cd2 = new D(C.M2);
cd2(-2);
Console.WriteLine();
//multi-casting delegate的一个效果
D cd3 = cd1 + cd2;
cd3(10);
Console.WriteLine();
C c = new C();
D cd4 = new D(c.M3);
cd3 += cd4;//cd3=cd1+cd2+cd4
cd3(30);
Console.WriteLine();
cd3 += cd1;
cd3(20);
Console.WriteLine();
cd3 -= cd1;
cd3(40);
Console.WriteLine();
cd3 -= cd2;
cd3 -= cd1;
cd3(50);
Console.WriteLine();
Console.ReadLine();
}
}
class C {
public static void M1(int i) {
Console.WriteLine("C.M1: " + i);
}
public static void M2(int i) {
Console.WriteLine("C.M2: " + i);
}
public void M3(int i) {
Console.WriteLine("C.M3: " + i);
}
}
}
0 0
- c#的委托(3)之多重委托
- c#委托----单一的委托
- C#委托-委托的使用
- C#学习笔记之多播委托
- C#的委托
- C#的委托
- C#里的委托
- C#委托的进化
- c#委托的使用
- c# 委托的应用
- C# 的委托总结
- C#委托的实现
- C#的委托
- C# 委托的理解
- C#委托的作用
- C#委托的使用
- C#的委托
- C# 委托的使用
- mysql自身运行日志文件详解
- Git学习笔记整理
- 27. Remove Element [easy]
- Opencv3.0-python的那些事儿:(一)、Opencv的图像和视频处理基本用法
- Reverse String
- c#的委托(3)之多重委托
- TextView 中 android:maxEms="" ,maxLine="",maxlenght="";的区别
- gitlab环境配置
- 关于eclipse项目转到android studio的经验
- malloc和new的十一个区别
- 监控Linux性能的18个命令行工具
- 利用bounds处理tableView顶部上下滑动
- java的Date日期类增加天数的静态方法。
- Android学习笔记六十二:Java并发编程:volatile关键字解析