public delegate void Del(string message);
static void Main(string[] args)
{
#region 調用委託
Del handler = DelegateMethod;
handler("Hello World");
#endregion
#region 委託的異步回調
Program TestCallBack = new Program();
TestCallBack.MethodWithCallback(1, 2, handler);
#endregion
}
#region 一般調用委託的方法
public static void DelegateMethod(string message)
{
System.Console.WriteLine(message);
}
#endregion
#region 委託的異步回調的方法
public void MethodWithCallback(int param1, int param2, Del callback)
{
callback("The number is: " + (param1 + param2).ToString());
}
#endregion