TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

EventHandler<T>

Not only is List one of the most useful generic types you'll find, EventHandler got me pretty *fired* up this evening as I was finishing up my Framework Design Guidelines book. And since the cute and fuzzy bunnies don't like me firing events, here's an example of EventHandler that "raises" an event.  :-)

public class EndOfWorldEventArgs : EventArgs {}

 

public class Foo {

    public event EventHandler<EndOfWorldEventArgs> EndOfWorld;

 

    public void SayFireEventInsteadOfRaiseEvent() {

        OnEndOfWorld(new EndOfWorldEventArgs());

    }

 

    protected void OnEndOfWorld(EndOfWorldEventArgs e) {

        EventHandler<EndOfWorldEventArgs> handler = EndOfWorld;

        if(handler != null) {

            handler(this, e);

        }

    }
}

 

 
Digg!

posted on Wednesday, October 19, 2005 8:09 PM

Feedback

No comments posted yet.