delegate C # the biggest role of the proxy is to bind events of the class to Process Programs .
before calling a function through a proxy, you must first check whether the proxy is empty ( null ). A function can be called unless it is null.
static methods or instance methods can be encapsulated in the proxy instance.
agent three steps:
A . custom proxy class: Delegate int mydelegate ();
B . then instantiate the proxy class: mydelegate d = new mydelegate (myclass. mymethod);
C . finally, call the method through the Instance Object: int ret = D ();
The following is an example.
Using system;
Using system. LINQ;
Using system. text;
Namespace consoleapplication1
{
// Declare delegate, define required signature.
Delegate void delegate (string message );
Class mainclass
{
// Regular method that macthes signature.
Static void delegatemethod (string message)
{
Console. writeline (Message );
}
static void main (string [] ARGs)
{< br> // instantiate delegate with named method.
delegate d1 = new delegate (delegatemethod);
// instantiate delegate with anonymous method.
delegate D2 = new delegate (string message) {console. writeline (Message) ;});
// invoke delegate D1;
d1 ("hello ");
// invoke delegate D2;
D2 ("world ");
}< BR >}< br> to be continued.