how to write example for delegate

Gow.Net
Posted by Gow.Net under C# category on | Points: 40 | Views : 818
 public class sample
{
public void methode1()
{
Console.WriteLine("You r in method1");

}
public void methode2()
{
Console.WriteLine("You r in method2");

}
public void methode3()
{
Console.WriteLine("You r in method3");

}
}

class Program
{

static void Main(string[] args)
{
sample s = new sample();
Console.WriteLine("Single Delegate");
Delegateexample obj_dgt = new Delegateexample(s.methode1);

Console.WriteLine("Multicast Delegate");
obj_dgt += new Delegateexample(s.methode2);
obj_dgt += new Delegateexample(s.methode3);
obj_dgt.Invoke();//invoke method


obj_dgt -= new Delegateexample(s.methode3);
obj_dgt.Invoke();//invoke method

}
}

Comments or Responses

Login to post response