using System;
using System.Collections.Generic;
using System.Text;
namespace test
{
//定义委托,它定义了可以代表的方法的类型
public delegate void ShowBirthplace(string name, string birthplace);
class Program
{
private static void city(string name,string city)
{
Console.WriteLine("姓名:"+name+";城市:"+city);
}
private static void town(string name, string town)
{
Console.WriteLine("姓名:"+name+";乡镇:"+town);
}
//注意此方法,它接受一个ShowBirthplace 类型的的方法作为参数
private static void Showbirthplace(string name, string birthname, ShowBirthplace birthplace)
{
birthplace(name,birthname);
}
static void Main(string[] args)
{
Showbirthplace("张三","北京",city);
Showbirthplace("李四","平安县",town);
}
}
}
运行程序如下: