using System;
using System.Collections.Generic;
using System.Text;
namespace EventDemo
{
public delegate void EventHandler();
/// <summary>
/// Custom Class
/// </summary>
public class MyClass
{
// Constructor
public MyClass(){}
// Define a event
public event EventHandler aEvent;
public void FireEvent()
{
if (aEvent != null)
{
aEvent();
}
}
}
class Program
{
/// <summary>
/// Application start
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.aEvent += new EventHandler(ProcessEvent);
obj.FireEvent();
obj.aEvent -= new EventHandler(ProcessEvent);
// No event will be fired now
obj.FireEvent();
Console.WriteLine("Done!");
Console.ReadLine();
}
public static void ProcessEvent()
{
Console.WriteLine("Trigger event");
}
}
}
using System;using System.Collections.Generic;using System.Text;namespace EventDemo{ public delegate void EventHandler(); /// /// Custom Class /// public class M