// Delegate a type definition keyword to define an abstract method.
// Instance pointer needs to be passed in the Process of instantiating this type.
// The result of Instantiation is to get a method pointer.
// The abstract method is used to define the Method Instance as a variable.
// Perform several tests based on this point of view.
// Test 1. Use the abstract method as a common variable
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Reflection;
Namespace ConsoleApplication1
{
Delegate string abstract method (string parameter );
Class SecondTest
{
Public abstract method variable;
Public SecondTest ()
{
// If you want to use this method variable, you must first instantiate it, And then instantiate the method variable during class instantiation.
Method variable = new abstract method (this. Method entity );
}
// Define an object here. The instance must be passed in following the delegate type instantiation process. This code must exist.
Public string method entity (string method parameter)
{
StringBuilder work content = new StringBuilder ();
If (method parameter = "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 (method parameter = "processing industry competition ")
{
Work content. AppendLine ("investigating competitors ");
Work content. AppendLine ("fight ");
}
Return work content. ToString ();
}
}
// In the preceding example, both "method variable" and "method entity" are published as public so that they can be seen in test2.
// The method object is called externally. This is easy to understand. The object method is called.
// Method variable published ?!! We use a variable to record changes not just to define one read later, but to store values.
// When it comes to changes, what is the effect of the changes in the method variable value?
// It should be the method variable pointer pointing to a change, that is, pointing to another method.
// Let's use another example to demonstrate this change.
}
// Call Method
String execution result;
SecondTest test2 = new SecondTest ();
// Directly call the method entity
Execution result = test2. method entity ("Operation World of Warcraft ");
Console. WriteLine (execution result );
// Call method Variables
Execution result = test2. method variable ("processing industry competition ");
Console. WriteLine (execution result );