namespace 委托例子
{
class Program
{
static void Main(string[] args)
{
Say("张三", ChineseSepaking);
Console.ReadKey();
}
//定义委托
public delegate void SpeakDelegate(string name);
public static void ChineseSepaking(string name)
{
Console.WriteLine(
string.Format("我的名字是{0},我是中国人!!",name)
);
}
public static void EnglishSepaking(string name)
{
Console.WriteLine(
string.Format("我的名字是{0},我是美国人!!", name)
);
}
public static void Say(string name,SpeakDelegate sd)
{
sd(name);
}
}
}
{
class Program
{
static void Main(string[] args)
{
Say("张三", ChineseSepaking);
Console.ReadKey();
}
//定义委托
public delegate void SpeakDelegate(string name);
public static void ChineseSepaking(string name)
{
Console.WriteLine(
string.Format("我的名字是{0},我是中国人!!",name)
);
}
public static void EnglishSepaking(string name)
{
Console.WriteLine(
string.Format("我的名字是{0},我是美国人!!", name)
);
}
public static void Say(string name,SpeakDelegate sd)
{
sd(name);
}
}
}