// Test 2. Change the variable value of the Method
// Here the delegate of test 2 is used without recreating a new one.
// Delegate string abstract method (string parameter );
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace ConsoleApplication1
{
Class ThirdTest
{
Public void DoTest ()
{
Original object instance = new original object ();
String execution result;
// Test direct method call
Execution result = object instance. original method entity ("Operation World of Warcraft ");
Console. WriteLine (execution result );
// Call the test method variable
Execution result = object instance. Method variable ("processing industry competition ");
Console. WriteLine (execution result );
// Change the method variable value
Object instance. Method variable = new abstract method (this. new Method entity );
Execution result = object instance. Method variable ("Work handover ");
Console. WriteLine (execution result );
}
New Method entity of private string (string method parameter)
{
StringBuilder work content = new StringBuilder ();
If (method parameter = "Work handover ")
{
Work content. AppendLine ("submit materials ");
Work content. AppendLine ("package and quit ");
}
Return work content. ToString ();
}
}
Class Original object
{
Public abstract method variable;
Public original object ()
{
// Instantiate method Variables
Method variable = new abstract method (this. original method entity );
}
// Define the original object
Public string original 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 ");
}
Else
{
Work content. AppendLine ("input parameter exception ");
}
Return work content. ToString ();
}
}
// Here we have seen some effects of changing the value of the method variable.
// Publish a method variable to the outside. When the variable value changes, the next call points to the changed method call.
// Variable operators include =, + =,-=, and so on.
// If the method variable is used, the redirection, multiple directions, and redirection of the method address pointer are removed.
// The method variables have been noticed and are not used in the original object itself.
// The example below adds the internal usage of the object.
}
// Test code
ThirdTest test3 = new ThirdTest ();
Test3.DoTest ();