代表和事件之间有什么区别? [英] What are the differences between delegates and events?

查看:30
本文介绍了代表和事件之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

委托和事件之间有什么区别?不是都持有对可以执行的函数的引用吗?

What are the differences between delegates and an events? Don't both hold references to functions that can be executed?

推荐答案

Event 声明为 delegate 实例添加了一层抽象和保护.此保护可防止委托的客户端重置委托及其调用列表,并且仅允许在调用列表中添加或删除目标.

An Event declaration adds a layer of abstraction and protection on the delegate instance. This protection prevents clients of the delegate from resetting the delegate and its invocation list and only allows adding or removing targets from the invocation list.

这篇关于代表和事件之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆