|
일일 결과물 | ||
3조 |
파울로 |
10-11-17 |
Multicast Delegate |
Multicast Delegate
Multicast Delegate is a delegate that can have more than one element in its invocation list.
Multicast Delegate is a special class.
A Multicast Delegate has a linked list of delegates, called an invocation list, consisting of one or more elements. When a multicast delegate is invoked, the delegates in the invocation list are called synchronously in the order in which they appear.
Example of Multicast Delegate
delegate int DelMulticast(string s);
class Program { static int DoMethod1(string s) { Console.WriteLine("Do Method 1"); return 0; } static int DoMethod2(string s) { Console.WriteLine("Do DoMethod 2"); return 0; } static void Main(string[] args) { string MyString = "Hello";
DelMulticast Multicast = null;
// Multicast Delegate... Multicast += new DelMulticast(DoMethod1); Multicast += new DelMulticast(DoMethod2);
//Remove Multicast Delegate... Multicast -= new DelMulticast(DoMethod2);
Multicast(MyString); } } |
Simple Example of Delegate
public delegate void MyDelegate(string s);
class Program { public static void PrintMsg(string msg) { Console.WriteLine("The message is:{0}", msg); } static void Main(string[] args) { MyDelegate del = new MyDelegate(PrintMsg);
del("Good Evening, Ladies and Gentleman...\n");
} } |
Simple Example of Delegate Add two numbers:
public delegate int Del_Sum(int a, int b);
class Program { static int Sum(int a, int b) { return a + b; } static void Main(string[] args) { Del_Sum dsOb = new Del_Sum(Sum);
Console.WriteLine("Please Enter two Number:"); int a = Int32.Parse(Console.ReadLine()); int b = Int32.Parse(Console.ReadLine());
int res = dsOb(a, b); Console.WriteLine("Result is:\n" + res); Console.ReadLine();
} } |
첫댓글 Up to now, i really dont know when we use it or why we have to use it.
but i'm working on it, to know well about it.
Thank you Professor
In program world, master knows slave.
but, slave don't knows master.
So master can call slave's method, slave can't call master method.
If you want that master do something and slave observes erase any event.
When any event erase, you want that slave call mater.
How to call master.