Invoking A Delegate

Posted by Akiii under C# category on | Points: 40 | Views : 970
Today i will tell you two ways to invoke a Delegate. First, i should give you a sample method :-

public static void Method1(string msg)
Console.WriteLine("Method1 : " + msg);

Now, we declare a Selagate :-

public delegate void TestDelegate(string msg);

Now, calling the method with the help of a Delegate object :-

static void Main(string[] args)
TestDelegate td = new TestDelegate(Method1);


In the above code, either you can use "Invoke" method or by directly calling the method with help of passing the parameter.

Please note that declaring a Delegate should be the first thing you do ! Here i am just siting an example, so please adhere to standards !

Thanks and Regards

Comments or Responses

Login to post response