为什么不使用,而不是继承EventArgs类的自定义类 [英] Why to not use a custom class instead of inheriting the EventArgs class

查看:157
本文介绍了为什么不使用,而不是继承EventArgs类的自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我为什么要使用使用自定义类,传递的事件数据时会做同样的工作,我的一个类继承自 EventArgs的类代替?

I'm wondering why should I use a class that inherits from the EventArgs class instead of using a custom class that will do the same job for me when passing event data?

推荐答案

您不要的有无的从 EventArgs的继承,但它允许人在使用你的类使用和处理,一般 *处理器(对象发件人,EventArgs五)声明。 如果不从 EventArgs的继承,那么他们必须使用显式类型

You don't have to inherit from EventArgs, but it allows people using your classes to use and handle generic *Handler(object sender, EventArgs e) declarations. If you don't inherit from EventArgs, then they have to use explicitly typed

*Handler(object sender, YairsFakeEventArgs e)

这同样适用于只使用自定义的代表,但他们有很多更明确的区别。

The same goes for just using custom delegates but they are a lot more explicitly different.

这篇关于为什么不使用,而不是继承EventArgs类的自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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