1.Delegate is type-safe, that is, errors can be detected at compile time, and similar reflection are of type unsafe.
Delegate are pointers to method addresses and do not distinguish between static and instance methods.
Delegate is defined outside of class, and this peer class includes the method that delegate to use.
2.Delegate allows covariant (covariance) and anti-covariance (contra-variance) of reference types. That
Delegate Object Mycallback (FileStream fs);
String Someothermethod (Stream s)
{
}
You can bind the Someothermethod method to a Mycallback delegate.
Covariance means that for a return type, a method can be derived from a delegate.
"Anti-covariance" means that for a parameter type, a delegate can be derived from a method.
3. The method callback of a delegate is generally written like this:
void CallBack (String p1, String p2, Testdele D)
{
if (d!= null)
{
D (P1, p2);
}
}
Here's a piece of crap: Using the callback method, you can pass in a null value to the Testdele parameter; In the callback method, if you want to determine if the D value is NULL, NULL cannot execute the method.
4.Delegate Essence: A class
The following delegate declares:
Public delegate string Testdele (int inttest);
Equivalent to this class:
public class TestDele:System.MulticastDelete
{public
testdele (int inttest, IntPtr method); Public
virtual String Invoke (int inttest);
Public virtual IAsyncResult beginresult (int inttest, AsyncCallback callback,
object);
public virtual void EndInvoke (IAsyncResult result);
}