0
点赞
收藏
分享

微信扫一扫

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

waaagh 2023-03-03 阅读 129


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 条评论