using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
ClassPeople cp = new ClassPeople();
cp.DoWork("王王",cp.SayChinese);
cp.DoWork("ray", cp.SayEnglish);
System.Console.ReadLine();
}
}
//委托实例
public delegate void SayDelegate(string name);
class ClassPeople
{
public void SayChinese(string name)
{
Console.WriteLine("你好," + name);
}
public void SayEnglish(string name)
{
Console.WriteLine("Hello," + name);
}
//注意此方法,它接受一个SayDelegate类型的方法作为参数
public void DoWork(string name, SayDelegate MakeSay)
{
MakeSay(name);
}
}
}