Thottam R. Sriram MSDN blog archive · 2006–2009

Simple sample for Events and Delegates

original post

I wanted to write a small sample to illustrate events and delegates. Here is a compact sample that illustrates it.

C#
using System;
public class EventSample
{
    public delegate void EventHandler();
    public event EventHandler myeh;
    public void Method()
    {
        Console.WriteLine("Inside Sample Method ... ");
    }
    public void OnChange()
    {
        myeh();
    }
    public static void Main()
    {
        EventSample es = new EventSample();
        es.myeh += new EventHandler(es.Method);
        es.OnChange();
    }
}

Comments

← All posts