58 lines
1.1 KiB
C#
58 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DelegateEventFuncAction
|
|
{
|
|
public class DelegateTest
|
|
{
|
|
public delegate void FunctionPointer();
|
|
|
|
private static void Print1()
|
|
{
|
|
Console.WriteLine("Print 1");
|
|
}
|
|
|
|
private static void Print2()
|
|
{
|
|
Console.WriteLine("Print 2");
|
|
}
|
|
|
|
private static void Print3()
|
|
{
|
|
Console.WriteLine("Print 3");
|
|
}
|
|
|
|
private static void Print4()
|
|
{
|
|
Console.WriteLine("Print 4");
|
|
}
|
|
|
|
private static void Execute(FunctionPointer fp)
|
|
{
|
|
fp();
|
|
}
|
|
|
|
public static void DoTest1()
|
|
{
|
|
Execute(Print1);
|
|
Execute(Print2);
|
|
Execute(Print3);
|
|
Execute(Print4);
|
|
}
|
|
|
|
public static void DoTest2()
|
|
{
|
|
// delegate chain
|
|
FunctionPointer fp = new FunctionPointer(Print1);
|
|
fp += Print2;
|
|
fp += Print3;
|
|
fp += Print4;
|
|
|
|
fp();
|
|
}
|
|
}
|
|
}
|