This article introduces the basic knowledge of the delegation, then further studies the Commission.
Delegate type
In fact, the beginning of the idea that the delegate type is a more difficult to understand the concept, how do not feel that the following "Assembleiphonehandler" is a type.
The code is as follows:
public delegate void Assembleiphonehandler ();
In the normal case, if we are to create a delegate type it should be:
The code is as follows:
public class AssembleIphoneHandler:System.MulticastDelegate
{
}
However, this type of writing is not compiled, and you are prompted not to derive subclasses from "System.MulticastDelegate".
In fact, this is the compiler that made a conversion for us, and when we declare a delegate type using the delegate keyword, the compiler creates a delegate type for us in the same way as the code snippet above.
Knowing these things, the understanding of the delegate type is easier, and the delegate type declared by delegate is a subclass derived from "System.MulticastDelegate".
Establish a chain of trust
Let's take a look at the establishment of the delegate chain and the changes to the invocation list, based on an example from the previous article.
The code is as follows:
Class Program
{
static void Main (string[] args)
{
Apple Apple = new Apple ();
Foxconn Foxconn = new Foxconn ();
Apple.assembleiphonehandler D1, D2, d3, d4 = null;
D1 = new Apple.assembleiphonehandler (Foxconn. Assembleiphone);
D2 = new Apple.assembleiphonehandler (Foxconn. Packiphone);
D3 = new Apple.assembleiphonehandler (Foxconn. Shipiphone);
D4 + = D1;
D4 + = D2;
D4 + = D3;
D4 ();
Console.read ();
}
}
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
Further understanding of Delegates in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23130.html
Related content C # get IP and determine if IP is in Interval C # THIS1?? üx?μ????? ó? ¨c# methods for arranging elements in an array a summary of how C # generates DLL files
C #, ASP. NET generic tool class Iswhat? (Can judge numbers, IDs, data types, etc.) C # the Tomato Clock countdown code written in C # implements a method to implement custom timing components in C # by automatically switching different SQLite DLL files under 32-bit, 64-bit systems
Further understanding of Delegates in C #