using System;

namespace ConsolePlay
{
    public class DelegateTester
    {
        public delegate void EventHandler(string strIn);
        public void raiseEvent (int intInput, EventHandler eventHandler)
        {
            if (intInput % 2 == 1)
                eventHandler (intInput + " is odd");
            else
                eventHandler (intInput + " is even");
        }

        public static void Main (string[] args)
        {
            DelegateTester delegateTester = new DelegateTester();
            DelegateProvider delegateProvider = new DelegateProvider();
            
            delegateTester.raiseEvent(5, delegateProvider.handleEvent);
            Console.WriteLine("Return to quit.");
            Console.ReadLine();
        }
    }

    public class DelegateProvider
    {
        public void handleEvent(string strIn)
        {
            Console.WriteLine("Event raised: " + strIn + " -- and handled");
        }
    }
}

Labels: