您的位置:首页 > 编程语言 > C#

[Note]CLR via C#3-Event and Delegate

2011-09-01 00:14 344 查看
I don't wanna talk about how those two features work. They are all important features of .Net Framework.

As we know, the event is a very special delegate, if you dig deeply and invesigate the code, you are gonna find the inside event is implemented by event.

The event is on the top of delegate and further encapsulated based on the delegate. and the delegate can do everthing that the event can do.

so the question is why we need the event, How 'special' the event is as opposed to the delegate,what the main difference is between them.

generally speaking, i think i got the point after some code and test:

The delegate is naked to the destination and the destination can do so many operations on it and also the distination can modify it while the event is further encapsulated based on the delegate and the destination can only listen to it.

actually, the event is one of the important uses of the delegate. another one of important uses of it is the asychonous process with the BeginInvode and EndInvoce.

The relationship between those two and the Design Pattern

We can implement the Factory Design Pattern by using the delegate.

actually, the event is the Observer Pattern.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: