January 2011
Intermediate to advanced
1648 pages
70h 30m
English
In our CountDown example, you’ve seen how to raise events using this pattern:
![]()
Looks right, doesn’t it? If nobody is listening for the event, MyEvent is null, and we should not attempt to invoke the delegate because that will cause the runtime to yell at us with an unfriendly NullReferenceException.
It might be surprising that the empty event handlers are being presented with null references. This is really due to the way the Combine and Remove methods on Delegate are implemented, but that just pushes the question further out: Why not just return a MulticastDelegate with an empty invocation ...
Read now
Unlock full access