一些事件的簡寫形式。
1、不需要創建委託。
public event EventHandler<CheckEventArgs > Playing;
public void Test(){
CheckEventArgs args=new CheckEventArgs ();
if(Playing!=null)
Playing(this,args);
}
2、不需要自定義參數。
public delegate void UserHandler(object sender, int count);
public event UserHandler handler;
3、虛方法的重要性。
public virtual void OnPlaying(object sender, CheckEventArgs args)
{
if (Playing != null)
{
Playing(this, args);
}
}
專門寫一個on的事件處理,以便其他繼承時,可重寫該方法,提供這樣一個接口。