The source code to call multiple methods from delegates is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Invoke del1:
Method1 called
Invoke del2:
Method2 called
Invoke del3:
Method1 called
Method2 called
Invoke del4:
Method2 called
Press any key to continue . . .
Explanation:
In the above program, we created a Sample class that contains three static methods Method1() and Method2(), and Main().
Method1() and Method2() are used to print a message on the console screen. In the Main() method we bind the methods with delegates.
In the above code, delegate del3 combine delegate del1 and del2. The delegate del3 will call method Method1() and Method2(). In the del4, we removed del1 from del3 then it will call only Method2().
Program:
The source code to call multiple methods from delegates is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a Sample class that contains three static methods Method1() and Method2(), and Main().
Method1() and Method2() are used to print a message on the console screen. In the Main() method we bind the methods with delegates.
In the above code, delegate del3 combine delegate del1 and del2. The delegate del3 will call method Method1() and Method2(). In the del4, we removed del1 from del3 then it will call only Method2().
need an explanation for this answer? contact us directly to get an explanation for this answer