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#

 Buy Now From Amazon


 Chapter List

  1. Why C#?

    I Strong Typing & Type Safety
  2. Strong Typing
    Why Strong Typing
  3. Value & Reference
  4.    Extract Value And Reference
  5. Structs & Classes
    Structs & Classes 
  6. Inheritance
  7. Interfaces & Multiple Inheritance
    Extract Interface
  8. Controlling Inheritance
    II Casting & Generics
  9. Casting - The Escape From Strong Typing
    Extract Casting I ***NEW!
  10. Generics
  11. Advanced Generics
  12. Anonymous & Dynamic
    III Functions
  13. Delegates
  14. Multicast Delegates
  15. Anonymous Methods, Lambdas & Closures
    IV Async
  16. Threading, Tasks & Locking
  17. The Invoke Pattern
  18. Async Await
  19. The Parallel For
    V Data - LINQ, XML & Regular Expressions
  20. The LINQ Principle
  21. XML
  22. LINQ To XML
  23. Regular Expressions
    VI Unsafe & Interop
  24. Interop
  25. COM
  26. Custom Attributes
  27. Bit Manipulation
  28. Advanced Structs
  29. Pointers 

Extra Material



kotlin book



or email your comment to:







Last Updated ( Friday, 29 July 2016 )