Event and delegate

就定义而言, CLR上是这样说的:

Event: a static event is a mechanism that allows a type to send a notification to listening types or listening objects,an instance event is a mechanism that allows an object to send a notification to listening types or listening objects.

从字面上看,事件通常就是响应(执行),一个(或一些)类型(type)或者对象(object)的状态(某些值)的改变,或者是执行一些操作。

一个事件通常由两个方法组成,它允许类型或者对象注册或者注释一些操作(method),另外,事件一般用代理(delegate)来维护(maintain)注册和注释的设置;

 

Deleagate: a type-safe mechanism which is used to callback functions

这个有些像C 的函数指针,不过C的函数指针不是安全的,因为在C中,一个non-member funcation 只是一内存地址,该地址不会附带任何其他的信息。像函数期望的变量个数,变量的类型,还有函数的返回值,以及调用该函数需要遵循的协议等等,而delegate在这些方面有严格的限制,所以是类型安全的。

posted @ 2009-01-16 10:24  路飞船长  Views(199)  Comments(0Edit  收藏  举报