在CLR via C#,傑弗裏裏希特給委託鏈的(第406)。下面的例子:委託鏈接是否必須以空委託開始?
internal delegate void Feedback(Int 32 value);
Feedback fb1 = new Feedback(method1); // in the book, these methods
Feedback fb2 = new Feedback(method2); // have different names
Feedback fb3 = new Feedback(method3);
Feedback fbChain = null;
fbChain = (Feedback) Delegate.Combine(fbChain, fb1);
fbChain = (Feedback) Delegate.Combine(fbChain, fb2);
fbChain = (Feedback) Delegate.Combine(fbChain, fb3);
爲什麼到Delegate.Combine
第一次調用都在一個空Delegate
通?下面是我本來以爲應該寫成:
Feedback fbChain = (Feedback) Delegate.Combine(fb1, fb2);
fbChain = (Feedback) Delegate.Combine(fbchain, fb3);
+1 - 好,準確和徹底的答案 – ANeves 2010-04-23 15:35:16