本文介绍了虚拟覆盖事件继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 嗨 我使用以下语法将事件从基类继承到子类,这些事件很好地工作(事件上的虚拟和覆盖关键字)。但我想知道它是否是一个支持的使用事件的方式,因为我从未在MSDN文档/样本中的任何地方使用它?!或者在我未来几年升级到.NET Framework 2.x时会崩溃 命名空间MyNamespac public delegate void MyDel( ) 公共类MyBase 公共虚拟事件MyDel MyEvent public void MyMethod2( MyEvent() 公共类MyDerived:MyBas //覆盖基类事件,以便它可以 //从孩子加薪(这里! 公共覆盖事件MyDel MyEvent public void MyMethod( {//提升事件。没有虚拟/覆盖关键字, //不允许子类在其基础clas中引发声明的事件 // br /> MyEvent() 感谢 JPRoo 解决方案 支持并记录好了。见 http ://msdn.microsoft.com/library/en...pspec_10_7.asp http://msdn.microsoft.com/library/en...pec_10_7_4.asp Mattias - Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ 请回复新闻组。 继承到子类,这些子类运行良好(虚拟和覆盖事件上的关键字)。但我想知道它是否是一个支持的使用事件的方式,因为我从来没有看到它在MSDN文档/样本中的任何地方使用过?或者在即将到来的几年中升级到.NET Framework 2.x时它会破坏吗? 虚拟/覆盖关键字, 引发声明的事件 HiI use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming yearsnamespace MyNamespacpublic delegate void MyDel()public class MyBasepublic virtual event MyDel MyEventpublic void MyMethod2(MyEvent()public class MyDerived : MyBas// Override base class event so that it can// be raise from child (here!public override event MyDel MyEventpublic void MyMethod({// Raise event. Without the virtual/override keywords,// child classes are not allowed to raise events declared// in their base clasMyEvent()ThankJPRoo 解决方案It''s supported and documented alright. See http://msdn.microsoft.com/library/en...pspec_10_7.asp http://msdn.microsoft.com/library/en...pec_10_7_4.aspMattias--Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/Please reply only to the newsgroup. base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years? can virtual/override keywords, to raise events declared 这篇关于虚拟覆盖事件继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 08:34