是什么在C#中的委托和事件之间的区别? [英] What is the difference between delegate and event in C#?

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

问题描述


可能重复:结果
什么是委托和事件之间的区别?






这问题,我在接受采访时得到了,我还是不知道答案是什么。结果
我将不胜感激任何想法!


< DIV CLASS =h2_lin>解决方案

我有一个文章上几乎完全



在简单地说,你能想到的事件作为一个有点像一个属性 - 但不是在的get / set操作,它已添加/删除。 。添加/删除的值总是委托引用



代表自己支持的操作:




  • 联合(链的多个委托实例)

  • 删除(再次分裂起来)

  • 调用(同步或异步)

  • 各种事情要做找出目标,调用列表等等



注意,代表本身不变的,所以合并/删除操作返回一个新委托实例,而不是修改现有的。


Possible Duplicate:
What is the difference between a delegate and events?

This question I got at an interview and I still don't know what the answer should be.
I would appreciate any thoughts!

解决方案

I have an article on pretty much exactly

In brief, you can think of an event as being a bit like a property - but instead of having get/set operations, it has add/remove. The value being added/removed is always a delegate reference.

Delegates themselves support operations of:

  • Combine (chain multiple delegate instances together)
  • Remove (split them up again)
  • Invoke (synchronous or asynchronous)
  • Various things to do with finding out the target, invocation list etc

Note that delegates themselves are immutable, so combine/remove operations return a new delegate instance rather than modifying the existing ones.

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

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