使用 ILDasm.exe 檢視 void Method(MyDelegate aMyDelegate) 的中間語言:

圖證明:編譯器確實生成對 MyDelegate.Invoke() 的呼叫指令。
以下兩種寫法編譯後完全相同:
// 寫法 1:隱式呼叫(編譯器自動生成 Invoke)
private void Method(MyDelegate aMyDelegate)
{
if (aMyDelegate != null) aMyDelegate();
}
// 寫法 2:顯式呼叫 Invoke
private void Method(MyDelegate aMyDelegate)
{
if (aMyDelegate != null) aMyDelegate.Invoke();
}
_target(目標物件)與 _methodPtr(方法指標)執行回調| 欄位 | 型別 | 用途 |
|---|---|---|
| _target | object | 實例方法的 this 參考;靜態方法為 null |
| _methodPtr | IntPtr | CLR 內部方法標識符 |
| _invocationList | object | 多播委派時的委派陣列參考 |
委派物件封裝「方法指標」與「目標物件」。呼叫委派實際上是呼叫其 Invoke() 方法,由 CLR 依據內部欄位執行正確的方法。