For me, delegation has always been something I have never mastered. It is widely used in many ways. I remember it was first introduced when I learned the thread, in my later studies, I had a question about how to handle parameters when registering multiple events and passing parameters. Of course, the actual results are generally guessed by people who have learned some points, but after all, it is speculation that they have never been tested and used, and they are always timid. Below is an example of mine.
Ps: the order of broadcast is added according to the order of broadcast. The next method is implemented only after the original parameters are modified for each broadcast. The following is the result, if needed, you can format the time, or sleep for one second each time. The time is different. It is troublesome to change the image ....
Code
Delegate void strFactory (ref string str );
Class Program
{
Static void Main (string [] args)
{
StrFactory fac = new strFactory (test );
Fac + = test;
String str = "startTime :";
Fac + = test;
Fac (ref str );
Console. WriteLine (str );
}
Static void test (ref string str)
{
Str + = string. Format ("{0} \ t", DateTime. Now. ToLocalTime (). ToString ());
}
}
Result: