本文介绍了委托问题,在调用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.
请帮帮我.
在工作期间,我想委托一个方法.
这是类Publisher
Hello all.
Please help me.
During my work, i want to delegate a method,.
This is class Publisher
public delegate void SaveAppontment(DateTime date, String s)
SaveAppointment sv =null;
if (sv != null)
{
sv.Invoke(DateTime.Now, "");
}
----------------------
我想从其他班级开始..
B类
========
在这里,我想在上面的委托中发送执行此工作的方法.
Publisher.SaveAppontment sd = method(date,s)//或其他什么东西,在这里我不在乎,我在乎发布者类,如果我使用的是正确的委托人!
----------------------
From my other Class, i want to do this..
CLASS B
========
Here i want to send the method that does the job in my delegate above.
Publisher.SaveAppontment sd = method(date, s)// or something,, i dont care here a lot, i care in the publisher class, if i using the delegtes right !!?
Is it possible ??
推荐答案
public delegate void SaveAppointmentDelegate(DateTime dt, string s);
public SaveAppointmentDelegate SaveAppointment;
public void FireSaveAppointmentEvent(DateTime dt, string s)
{
if (SaveAppointment != null) SaveAppointment(dt,s);
}
您可以通过以下方式将处理程序添加到SaveAppointment:
You add a handler to the SaveAppointment by the following:
SaveAppointment += SaveAppointmentEventHandler;
这篇关于委托问题,在调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!