EventArgs问题... [英] EventArgs question...

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

问题描述

因此,我为一个类声明了一个新事件,并且到了需要定义事件args的地步.我真正需要传递的只是一个文本字符串.

现在,我通常遵循一些勤奋的最佳实践指南,我记得前一阵子曾读过该指南,说您应该定义一个新类来保存事件args,而不是像这样仅将事件数据传递给该类:

So I am declaring a new event for a class and I get to the point where I need to define the event args. All I really need to pass through is a text string.

Now I usually follow some diligent best practice guide that I remember reading awhile ago that says you should define a new class to hold your event args instead of just passing the event data along in the class like so:

Public Event EventName (sender As Object, message As String)



所以我这样做:



So I do it like so:

Public Class EventNameEventArgs : Inherits EventArgs <br /><br />   Public Property Message() as String <br /><br />End Class <br /><br />Public Event EventName (sender as Object, e As EventNameEventArgs) 



问题是,我感觉自己是唯一的人这样做的星球:),但我还没有看到其他人没有这样做的代码.我只是想在这里为小组达成普遍共识...

我倾向于认为是的,这是一个好主意,因为它允许在不破坏现有代码的情况下添加新的参数.引用了事件,但是...

有评论吗?

请问是否也没有关于VB的评论...



The problem is, I have the feeling that I am the only person on the face of the planet doing this :), but I have not seen any code form others that does NOT do this. I just want to get a general consensus for the group here...

I tend to think that yes, it is a good idea because it allows for the addition of new arguments latter on without breaking the existing code that references the event but...

Comments? Flames?

Please, no remarks about VB either...

推荐答案

这将有助于:
This will help: Event Arguments (EventArgs)[^]


这篇关于EventArgs问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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