[Mono-list] Howto: Build custom events

Michał Ziemski rook at roo.k.pl
Sat Sep 1 12:14:04 EDT 2007


Basically you declare:

class Foo
    public delegate void SimpleDelegate();
    public event SimpleDelegate TerribleEvent;
    protected void OnTerribleEvent()
      if (TerribleEvent != null)

and you use OnTerribleEvent to fire the event;

You connect to the event from another class by:
FooInstance.TerribleEvent += MyMethodMatchingSimpleDelegateSignature();

Michał Ziemski

Danny Stolle pisze:
> Hi all,
> this perhaps sounds really dumb, but i have some trouble writing events
> and raising them using C#. i have no trouble on writing classes having
> its methods, properties, etc. but when it comes to events, i don't know
> how to use them.
> programming in VB6, I used Microsoft back then, was easy. you declared
> the event you wanted, like: public event StatusOK(string message)
> within the class you could raise the event by using: RaiseEvent
> <eventname>: e.g. RaiseEvent StatusOK.
> Now I am off VB and using C#. But can somebody please point me out to
> some good documentation on how to write custom events for classes and
> how to raise them in your apps.
> Thanx a lot.
> Danny
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

More information about the Mono-list mailing list