// Pass method variables as function parameters, also called callback
Using System;
Using System. Collections;
Using System. Collections. Generic;
Using System. Text;
Namespace ConsoleApplication1.SeventhTest
{
Class SeventhTest
{
Public void DoTest ()
{
Lead Zhu Ge = new lead ();
Subordinate Wei = new subordinate ();
Zhu Ge. Add a task (Wei. His work, "Operation World of Warcraft ");
Zhu Ge. Processing the task ();
Console. ReadLine ();
Zhu Ge. Add tasks (Wei, his own job, "handling industry competition ");
Zhu Ge. Processing the task ();
}
}
Delegate string delegate task (string task content );
Class leader
{
Private Hashtable task list;
Add a public void task (delegate a task, string Task Type)
{
If (task list = null)
Task List = new Hashtable ();
Task list [Task Type] = one task;
}
Public void processing task ()
{
Foreach (DictionaryEntry task item in task list)
{
String result = (delegate task) task item. Value) (string) task item. Key );
Console. WriteLine (result );
}
}
}
Class subordinates
{
Public string work (string task content)
{
StringBuilder work content = new StringBuilder ();
If (Task content = "Operation World of Warcraft ")
{
Work content. AppendLine ("arrange device procurement ");
Work content. AppendLine ("Recruitment customer service, induction training ");
Work content. AppendLine ("advertising ");
Work content. AppendLine ("game market ");
Work content. AppendLine ("launch activity ");
Work content. AppendLine ("............ ");
}
Else if (Task content = "processing industry competition ")
{
Work content. AppendLine ("investigating competitors ");
Work content. AppendLine ("fight ");
}
Return work content. ToString ();
}
}
// In the previous example, the leader made public his own affairs, and his subordinates made further efforts to deal with the affairs disclosed by the leader.
// In this example, the leader receives and handles external tasks.
// One is open to the outside, and the other is receive internally.
}