delegate void MyDelegate();
void Method1(){//this is a method}void Method2(){//this is another method}//here we are creating a a new object and attaching Method1 to it.MyDelegate dlg1 = new MyDelegate(Method1);//now attaching another methoddlg1+= Method2;//If you call the delegate now, all the methods refered by it will be executed.dlg1( );//Method1 and Method2 are executed in the same order as they are attached to the delegated.
using System;namespace ConsoleApplication45{ class SalesItem { int stock; public delegate void onLowStock(); //delegate that holds StockLow events public event onLowStock StockLow; //StockLow event is attached to the delegate onLowStock public SalesItem(int stock) { this.stock = stock; } public void Add(int qty) { stock += qty; } public void Remove(int qty) { if (stock < qty) { StockLow(); //calling the event } stock -= qty; } } class Program { static void Main(string[] args) { SalesItem s1 = new SalesItem(10); s1.StockLow += new SalesItem.onLowStock(s1_StockLow); //new event handler is attached to the StockLow event s1.Remove(5); s1.Add(2); s1.Remove(25); } static void s1_StockLow() { Console.WriteLine("Item s1 is out of stock"); } }}