Multicast Delegates and Events
Written by Mike James   
Friday, 24 June 2016
Article Index
Multicast Delegates and Events
Generic Events

Generic and Standard Events

Of course most of us simply make use of predefined events but there has been a change in the way that this works. Originally we needed a delegate type for each even slightly different even or we just passed object types to allow the event handler to work with a range of types. A better solution is to use generics and this is the approach now taken by the framework classes.


For example, the original standard event handler was no generic:

public delegate void EventHandler(
                     object sender, EventArgs e);

Using object as the first parameter allowed any class to raise the event and still notify the users of the event handlers what had raised the event. The new generic version is:

public delegate void
  (object sender, TEventArgs e)
       where TEventArgs : EventArgs;

which still leaves the sender untyped. A better version is:

public delegate void
      (S sender,A args);

In this case the event would be set up using something like:

public event GenericEventHandler
          <MyClass,MyArgs> MyNewEvent;

Generics significantly simplify the implementation of events and by reducing the need to pass an object type increase overall type safety.


Deep C#


 Chapter List

  1. Value And Reference
  2. Dynamic C#
  3. Passing Parameters
  4. Inheritance 
  5. Casting – the escape from strong typing
  6. Controlling Inheritance ***NEW
  7. Delegates
  8. Multicast delegates and events
  9. Anonymous Methods, Lambdas And Closures
  10. Take Exception To Everything
  11. What's The Matter With Pointers?
  12. Generics
  13. Structs
  14. The LINQ Principle
  15. XML in C#
  16. Linq and XML
  17. Regular Expressions in depth
  18. Bit Manipulation
  19. Async, Await and the UI problem
  20. The Invoke pattern
  21. The Parallel For
  22. Deep C# - Custom Attributes In C#
  23. Not so complex numbers in C#
  24. Getting Started With .NET IL
Multicast delegates and events
Tuesday, 25 May 2010
Article Index
Multicast delegates and events
Generic Events

Multicast delegates are useful in their own right but they also form the basis on which the C# event system is built. We take a close look at how they work and how to use them. For example, did you know you could add and subtract delegates?





or email your comment to:







Last Updated ( Friday, 29 July 2016 )