【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
最近学到委托了,贴上代码吧。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Delegate
{
public delegate void GreetingDelegate (string name);
class Program
{
public static void MakeGreeting (string name,GreetingDelegate gd)
{
gd(name);
}
public static void EnglishGreeting(string name)
{
Console.Write("Hello," + name + "\n");
}
public static void ChineseGreeting(string name)
{
Console.Write("你好," + name + "\n");
}
static void Main(string[] args)
{
MakeGreeting("World", EnglishGreeting);
MakeGreeting("世界", ChineseGreeting);
Console.ReadKey();
}
}
}
推荐扩展阅读:
让我们一同学习C#,一同进步!
来源:oschina
链接:https://my.oschina.net/u/818783/blog/109883