delegate是个比较生僻的单词(其实是我英语差~)。那先看看简要的来自金山词霸的解释:
delegate
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->名词 n.
* 1.代表, 代表团成员
He is one of the delegates to the conference.
他是与会代表之一。
及物动词 vt. 其他读音:[ˈdeliɡeit]
* 1.任命或委派…为代表
He delegated me to perform. a task.
他委派我去执行一项任务。
* 2.托付
* 3. 授(权);把(工作、权力等)委托(给下级);选派(某人做某事)
delegate
n
a person chosen or elected to act for or represent another or others, esp at a conference or meeting
a representative of a territory in the US House of Representatives
vb
to give or commit (duties, powers, etc) to another as agent or representative; depute
to send, authorize, or elect (a person) as agent or representative
to assign (a person owing a debt to oneself) to one's creditor in substitution for oneself
就跟有一种类叫String一样,有一种类叫Delegate,String类的对象一般都是字符序列,而Delegate类的对象一般是某种 类型的函数,只要一个函数的类型,包括参数定义跟返回值类型,跟声明委托时的定义是一致的,我们就可以把这个函数名传递给某个这种委托类的实例,通过这个 委托类的实例来操纵这个函数。也就是说实现了根据类型来按需调用一系列的同类型函数。
具体的实现语法和所谓的委托链,multicast delegate都可查阅具体的文章即可。
设计这么一个委托机制,倒底给编程带来了哪些方便,还需要在实践中体会。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-625748/ ,如需转载,请注明出处,否则将追究法律责任。