All pastes #964842 Raw Edit

Unnamed

public text v1 · immutable
#964842 ·published 2008-03-31 16:25 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public delegate void SomeEvent(object sender, EventArgs e);

    class EventListener
    {
        public void EventFired(object sender, EventArgs e)
        {
            Console.WriteLine("Event recieved!");
        }

        public void Attach(EventSender es)
        {
            es.EventRecieved += new SomeEvent(this.EventFired);
        }
    }

    class EventSender
    {
        public event SomeEvent EventRecieved;

        public void DoStuff()
        {
            if (EventRecieved != null)
                EventRecieved(this, EventArgs.Empty);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            EventListener el = new EventListener();
            EventSender es = new EventSender();
            el.Attach(es);
            es.DoStuff();
        }
    }
}