using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Delgates_Ex1 { public delegate void ExampleDelgate(int x, int y); class Democlass { public void Add(int x, int y) { Console.WriteLine(x+y); } public static void mul(int x, int y) { Console.WriteLine(x*y); } } class Program { public static void Sub(int x, int y) { Console.WriteLine(x -y); } static void Main(string[] args) { Democlass d = new Democlass(); ExampleDelgate e1 = new ExampleDelgate(d.Add); // I know here I am doing instantiation of the delegate ExampleDelgate e2 = new ExampleDelgate(Democlass.mul); ExampleDelgate e3 = e1 + e2; e3 = e1 + e2 + e3; // When I execute the line i get twice i.e out put would be 30 200 30 200 can any one explain me what is happening here. Basically I am trying to //understand Mutlicast delegates and when i remove +e3 i just get only once e3(20, 10); // and here I am doing Delegate Invocation } } }
ExampleDelgate e3 = e1 + e2;
Add
mul
e3(20, 10);
Add(20, 10)
mul(20,10)
30 , 200
e3 = e1 + e2 + e3;
e3+= e1 +e2;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)