学习笔记:委派 和 事件(一)
2007-02-07 17:14
288 查看
using System;
using System.Collections.Generic;
using System.Text;
//Declare Delegate -- defines requried signature:
//声明一个委派
delegate void SampleDelegate(string massage);
namespace DelegateConsoleApp
{
class Program
{
// Regular method that mathes signature:
//事先声明一个委派
static void SampleDelegateMethod(string message)
{
Console.Write(message);
}
static void Main(string[] args)
{
//Instantiate delegate with named method
//实例化一个委派的d1,指出d1调用一个已经定义的方法
SampleDelegate d1 = SampleDelegateMethod;
//Instantiate delegate with anonymouns method:
//实例化一个委派的d2,指出d2 调用一个匿名的方法。
SampleDelegate d2 = delegate(string message)
{
Console.WriteLine(message);
Console.WriteLine("I am Superman");
};
// Invoke delegate d1:
d1("Hello");
// Invoke delegate d2:
d2(" World");
}
}
}
using System.Collections.Generic;
using System.Text;
//Declare Delegate -- defines requried signature:
//声明一个委派
delegate void SampleDelegate(string massage);
namespace DelegateConsoleApp
{
class Program
{
// Regular method that mathes signature:
//事先声明一个委派
static void SampleDelegateMethod(string message)
{
Console.Write(message);
}
static void Main(string[] args)
{
//Instantiate delegate with named method
//实例化一个委派的d1,指出d1调用一个已经定义的方法
SampleDelegate d1 = SampleDelegateMethod;
//Instantiate delegate with anonymouns method:
//实例化一个委派的d2,指出d2 调用一个匿名的方法。
SampleDelegate d2 = delegate(string message)
{
Console.WriteLine(message);
Console.WriteLine("I am Superman");
};
// Invoke delegate d1:
d1("Hello");
// Invoke delegate d2:
d2(" World");
}
}
}
相关文章推荐
- jQuery 学习笔记 事件委派
- UCOS2学习笔记:对于信号量,互斥信号量,事件标志组的个人理解
- Cocos2d-x学习笔记(二十六)之 按键事件
- Node.js学习笔记之三:事件_EventEmitter
- 2017补全计划-事件队列-学习笔记
- 委托、事件学习笔记
- Ext学习笔记3-事件及组件
- nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers
- VS2013MFC单文档工程学习笔记三 - 按钮添加响应事件
- Extjs学习笔记之八——继承和事件基础
- wxWidgets 学习笔记(3) 事件驱动(II)
- 第九章(4)-事件访问器-学习笔记
- android-学习笔记之按钮事件
- uCOS-II 学习笔记之事件管理--------信号量管理相关函数的学习
- C#开发学习笔记:编写自定义Button控件的自定义事件
- HTML5学习笔记(二十五):事件
- input子系统学习笔记九 evdev输入事件驱动分析
- wss3 sdk学习笔记四:事件处理
- 【js基础】js事件对象学习笔记
- 学习笔记——Event对象和事件冒泡