C# 委托的使用(指向函数的指针)

waaagh

关注

阅读 129

2023-03-03


using System;

namespace ConsoleApplication19
{
class Program //so easy
{
public delegate void Del(string message);
public static void DelegateMethod(string message)
{
Console.WriteLine(message);
}
public static void MethodWithCallback(int param1, int param2, Del callback)
{
callback("The number is: " + (param1 + param2).ToString());
}
static void Main(string[] args)
{
// Instantiate the delegate.
Del handler = DelegateMethod;

// Call the delegate.
//handler("Hello World");
MethodWithCallback(1, 2, handler);
}

}
}


精彩评论(0)

0 0 举报