static void Main(string[] args) { // Normal Methos Call getName("By Normal Method call - Abhishek Singh "); //Method Call using delegates myTestDel del = new myTestDel(getName); del("By Delagete call-Abhishek singh"); del.Invoke(" Using Invoke - Abhishek Singh "); del = new myTestDel(getLocation); del("Mumbai"); // Mutlticast implementation with void return type TestMutliCast delmultiCast = new TestMutliCast(Method1); delmultiCast += Method2; delmultiCast(); // Mutlticast implementation with void return type myTestDel testMulti = new myTestDel(getName); testMulti += getLocation; testMulti("Abhi"); // Mutlticast implementation with int return type TestMutliCastint intMulti = new TestMutliCastint(Method3); intMulti += Method4; int i = intMulti(); Console.WriteLine("Return Value is " + i); Console.ReadLine(); }
// public delegate int FunctionDelegate(int a, int b); static void Main(string[] args) { #region Simple Implementation //FunctionDelegate del = new FunctionDelegate(Method); FunctionDelegate del = Method; //del(2, 2); //del.Invoke(2, 2); Console.WriteLine(del(2, 2)); //as a function parameter Console.WriteLine(Marks(del)); #endregion #region Multicast Implementation // Mutlticast implementation with void return type TestMutliCast delmultiCast = Method1; delmultiCast += Method2; delmultiCast(); // Mutlticast implementation with int return type TestMutliCastint intMulti = Method3; intMulti += Method4; intMulti += Method5; int i = intMulti(); Console.WriteLine("Return Value is " + i); #endregion }