Multicast Delegate
Sat Oct 16 2021 16:38:55 GMT+0000 (Coordinated Universal Time)
Saved by
@funcProgramming
using System;
delegate void CustomDel(string s);
class TestClass
{
static void Hello(string s){
Console.WriteLine($" Hello, {s}!");
}
static void Goodbye(string s){
Console.WriteLine($" Goodbye, {s}!");
}
static void Main()
{
CustomDel hiDel, byeDel, multiDel, multiMinusHiDel;
hiDel = Hello;
byeDel = Goodbye;
multiDel = hiDel + byeDel;
multiMinusHiDel = multiDel - hiDel;
Console.WriteLine("Invoking delegate hiDel:");
hiDel("A");
Console.WriteLine("Invoking delegate byeDel:");
byeDel("B");
Console.WriteLine("Invoking delegate multiDel:");
multiDel("C");
Console.WriteLine("Invoking delegate multiMinusHiDel:");
multiMinusHiDel("D");
}
}
/* Output:
Invoking delegate hiDel:
Hello, A!
Invoking delegate byeDel:
Goodbye, B!
Invoking delegate multiDel:
Hello, C!
Goodbye, C!
Invoking delegate multiMinusHiDel:
Goodbye, D!
*/
content_copyCOPY
Comments