I wrote a lot of code, but almost never wrote code for the Delegate/event/thread parameter passing application.
Therefore, it is easy to understand and forget.
Today I reviewed it again.
Therefore, write down the code in the simplest way to help you understand it.
1. Passing parameters by thread [several simple lines of code]
1 static void main (string [] ARGs)
2 {
3 if (threadpool. queueuserworkitem (New waitcallback (program. writepara), "this is the passed parameter "))
4 {
5 console. writeline ("OK :");
6 console. Read ();
7}
8
9}
10 protected static void writepara (Object para)
11 {
12 console. writeline ("Hello:" + para );
13}
14
15
2. Delegate/event
1 public class Program
2 {
3 delegate void callfunction (Object para); // defines the delegate [This is a sample of defining a method. It is simply understood as static with Delegate]
4 Private Static event callfunction callevenhandle; // defines an event. [simple understanding: events must be delegated.]
5 static void main (string [] ARGs)
6 {
7 // call the delegate. the previously defined image method. Here a new instance is provided, which is similar to the new function of Js.
8 callfunction cf = new callfunction (writepara );
9 cf. Invoke ("Goodmorning ");
10
11
12 // call the event. Press the "tab" key after adding "+ =". It is easy to use.
13 callevenhandle + = new callfunction (writepara );
14 callevenhandle ("cyq ");
15
16 // console. Read ();
17}
18
19 protected static void writepara (Object para)
20 {
21 console. writeline ("Hello:" + para );
22}
23}
24