本文介绍了事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 基类中的我已经声明了以下事件处理程序: 公共抽象类MyBaseClass :: MarshalByRefObject { ..... 公共活动EventHandler OnMsgSent; .... } 在派生类中,我尝试按以下方式调用此事件: public override void MsgSent() { if(OnMsgSent!= null) { GbMessageEventArgs e = new GbMessageEventArgs(this); e.InfoString ="消息已成功发送!; OnMsgSent(this,e); } } 但是当我编译这个时,我收到以下错误消息: "事件,< my namespace>。< base class> ; .OnMsgSent''只能出现在 左手边的+ = ...." 我做错了什么? 感谢提示。 Rainer Hi, in a base class I have declared the following event handler: public abstract class MyBaseClass : :MarshalByRefObject{.....public event EventHandler OnMsgSent;....}In a derived class I try to call this event in the following way: public override void MsgSent(){if(OnMsgSent != null){GbMessageEventArgs e = new GbMessageEventArgs(this);e.InfoString = "Message was successfully sent!";OnMsgSent(this,e);}} but when I trie to compile this, I get the following error message:"The event ,<my namespace>.<base class>.OnMsgSent'' can only appear on theleft hand side of += ...." What is it I am doing wrong? Thanks for hints.Rainer解决方案 这篇关于事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 13:46