casting event handlers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darren

    casting event handlers

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


    public event System.EventHan dler MyEvent;

    private void SomeFn()
    {
    MulticastDelega te d1 = (MulticastDeleg ate)this.MyEven t;

    // this line won't compile
    MulticastDelega te d2 = (MulticastDeleg ate)this.Load;
    }
  • Mattias Sjögren

    #2
    Re: casting event handlers

    >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

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...