0
在C#上工作。爲什麼委派事件的通用方法不適用於錯誤消息方法名稱預期
我的委託和事件是波紋管
#region delegate event
#region
public delegate void NotifynextDeviceReceivedDelegate(CustomEventArgs customEventArgs);
public event NotifynextDeviceReceivedDelegate NotifynextDeviceReceivedEvent;
#endregion
#region
public delegate void NotifynextDeviceedDelegate(CustomEventArgs customEventArgs);
public event NotifynextDeviceedDelegate NotifynextDeviceedEvent;
#endregion
#region
public delegate void NotifynextReceiveddDelegate(CustomEventArgs customEventArgs);
public event NotifynextReceiveddDelegate NotifynextReceiveddEvent;
#endregion
#endregion
要調用我用波紋管語法,它的工作完美
if (NotifynextDeviceReceivedEvent != null)
{
CustomEventArgs customEventArgs = new CustomEventArgs(receivedMessage, receivedTopic);
//Raise Event. All the listeners of this event will get a call.
NotifynextDeviceReceivedEvent(customEventArgs);
}
需要寫相同的上述語法所有事件委託的所以,我決定編寫一般事件來調用它們,如下圖:
InvokeEvents<NotifynextDeviceReceivedDelegate>(receivedMessage,receivedTopic,NotifynextDeviceReceivedEvent)
public static InvokeEvents<T>(string receivedMessage,string receivedTopic, T notifynextDeviceReceivedEvent)
{
if (notifynextDeviceReceivedEvent != null)
{
CustomEventArgs customEventArgs = new CustomEventArgs(receivedMessage, receivedTopic);
notifynextDeviceReceivedEvent(customEventArgs);//here is the problem show me error message
}
}
在InvokeEvents方法爲什麼notifynextDeviceReceivedEvent告訴我錯誤方法名稱預計
[mcve]在這裏非常有幫助,因此我們可以將您的代碼複製/粘貼到IDE中,並查看您看到的完全相同的錯誤。 –