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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top