casting event handlers

  • Thread starter Thread starter Darren
  • Start date Start date
D

Darren

Why can I cast an event I declare but not one defined in the Form class


public event System.EventHandler MyEvent;

private void SomeFn()
{
MulticastDelegate d1 = (MulticastDelegate)this.MyEvent;

// this line won't compile
MulticastDelegate d2 = (MulticastDelegate)this.Load;
}
 
Why can I cast an event I declare but not one defined in the Form class

Inside a class that defines an event, the event name gives you access
to the underlying delegate.

Outside the class you only get to add and remove handlers, no direct
access to the delegate field.



Mattias
 
Back
Top