委派是一個**密封類別**,繼承自 System.MulticastDelegate,再繼承 System.Delegate。
public DelegateType(object target, IntPtr methodPtr)。Invoke:同步呼叫,簽名與委派一致。BeginInvoke:非同步啟動,回傳 IAsyncResult,參數含 AsyncCallback、object state。EndInvoke:取得非同步結果,參數含 out/ref 參數與 IAsyncResult。.class auto ansi sealed nested public MyEventHandler
extends [mscorlib]System.MulticastDelegate
{
}
說明委派可在命名空間層級或類別內部定義,因為本質上就是類別。
MyEventHandler handler = new MyEventHandler(staticCall);
// 呼叫 MyEventHandler(object, IntPtr)
// → MulticastDelegate(object target, string method)
// → Delegate(object target, string method)
MulticastDelegate 維護呼叫清單,+=/-= 操作清單,Invoke 依序執行。
委派非關鍵字而是類別,理解其繼承體系與四大方法簽名,是掌握事件模式、非同步程式設計、回呼機制的基石。