So here I will use the C # event to describe the Delegate (Delegate ). Let's take a look at the sample code: Code public delegate void ProcessEventHandler (string name );
Public class CharlesLog
{
Public event ProcessEventHandler processEvent;
Public void ProcessHandler (string name)
{
If (processEvent! = Null)
{
ProcessEvent (name );
}
Else
{
ProcessEvent = new ProcessEventHandler (DefaultHandler );
ProcessEvent (name );
}
}
Public void DefaultHandler (string name)
{
Console. WriteLine ("default Process! ");
}
}
Class Program
{
Static void Main (string [] args)
{
CharlesLog charlesLog = new CharlesLog ();
CharlesLog. processEvent + = new ProcessEventHandler (CustomProcess );
CharlesLog. ProcessHandler ("CharlesChen ");
}
Public static void CustomProcess (string name)
{
Console. WriteLine ("custom Process! ");
}
}
According to this Demo, some important points need to be paid attention to for delegation and events. I will list them here:1. The above delegate instantiation is. net 1.1 Syntax: (Note: As the Net version is upgraded, the syntax for delegation instantiation is simplified. In 2.0, there are anonymous methods and 3.0 Lambda expressions that are more in line with human languages. CharlesLog. processEvent + = new ProcessEventHandler (CustomProcess); 2. Statement event Syntax: "modifier & r