Does delegate chaining have to start with a null Delegate?

Posted by MCS on Stack Overflow See other posts from Stack Overflow or by MCS
Published on 2010-04-23T14:28:49Z Indexed on 2010/04/23 14:33 UTC
Read the original article Hit count: 301

Filed under:
|

In CLR via C#, Jeffrey Richter gives the following example of delegate chaining (pg. 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);

Why does the first call to Delegate.Combine have to pass in a null Delegate? Here's how I would have thought it should be written:

Feedback fbChain = (Feedback) Delegate.Combine(fb1, fb2);
fbChain = (Feedback) Delegate.Combine(fbchain, fb3);

© Stack Overflow or respective owner

Related posts about c#

Related posts about delegates