A Simple Console Application to understand "Delegates"

Posted by Prabhukiran345 under ASP.NET category on | Points: 40 | Views : 1181
class Program
// events programs should not contain static methods

// ** single event can't handle multiple delegates (can handle only one delegate)

public delegate void Mydel(string str);
public event Mydel Myevent;

public delegate void Mydel2();
public event Mydel2 Myevent2;

public void show(string str)
Console.WriteLine("show method {0}", str);
public void Display()
Console.WriteLine("display method");
public void Result()
Myevent += new Mydel(show);
Myevent2 += new Mydel2(Display);
Myevent("this is my struggle");

static void Main(string[] args)
Program Pa = new Program();



OutPut Will Be:

Show Method This is my struggle
display Method

Comments or Responses

Login to post response