事件
//定义事件
public event EventHandler<EventArgs> ExamStarted;
//触发事件时,应防止检测事件不为空,但检测后却为空的可能性。用赋值给一个变量来防止
protected virtual void OnExamStarted()
{
ExamEventHandler handler;
try {
handler = ExamStarted;
// Invoke the event
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
catch (System.Exception exception)
{
// do something to handle the exception
}
}
public class EventArgsT<t>: EventArgs
{
public EventArgsT(t Target)
{
TargetObject = Target;
}
public t TargetObject
{
get; set
}
}
浙公网安备 33010602011771号