什么是自定义事件的需要 [英] what is the need of custom event

查看:85
本文介绍了什么是自定义事件的需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多关于在c#中创建和处理自定义事件的文章。但是在每种情况下我都看到他们正在调用一个委托,而要执行的主要内容是在一个函数中编写的。这个函数被调用事件。



但我的问题是我为什么要使用活动?我可以直接在需要的地方调用该功能。



所以你能提供一篇文章,我可以看到创建活动的实际和实际目的。我需要这样讨论-------



1)这是事件的工作和

2)这个东西不能通过调用函数来实现,或者如果我们调用一个函数这就是约束。

I have seen so many articles on creating and handling custom events in c#.But in every case I'm seeing they are calling a delegate and the main thing which is to be executed is written in a function.That function is called by the event.

But my question is why should I use an event?I can call the function directly where needed.

So can you provide an article where I can see the actual and practical purpose of creating event.I need discussion in this way-------

1)this is the work of event and
2)this thing can not be achieved by calling function or if we call a function this is the constraints.

推荐答案

例如,当你想在开发这个功能时给一个你不认识的人创建通知时,你可以使用一个事件。



也许看到一个按钮。此Control创建/触发可以使用但不必使用的几个事件。按钮的开发人员不知道是否有人会使用这个 - 但他给了这个可能性......
You use an Event for example when you want to create a Notification to a someone you don't know while developing the function.

Perhaps see a Button. This Control creates/fires several Events which COULD be used but NOT MUST be used. The Developer of the Button didn't know if someone will use something of this - but he gave the possibility ...


看看这个:在两个表格之间转移信息,第2部分:从孩子到父母 [ ^ ] - 它使用一个事件在两个之间传递数据表格不违反OOP规则。
Have a look at this: Transferring information between two forms, Part 2: Child to Parent[^] - it uses an event to pass data between two forms without breaching OOPs rules.


这篇关于什么是自定义事件的需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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