using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 委托
{
delegate void AnimalPlay(string name);//委托 格式必须与要委托的函数相似
class Program
{
static void RunCircus(AnimalPlay animalPlay,string name)//函数做参数
{
animalPlay(name);
}
static void Main(string[] args)
{
AnimalPlay animalPlay = new AnimalPlay(DogAct);//指定委托哪个函数
RunCircus(animalPlay, "dawa");//执行函数
}
static void DogAct(string name )
{
Console.WriteLine("hello,I am " + name + "!");
Console.WriteLine("wangwangwang");
}
static void CatAct(string name)
{
Console.WriteLine("hello,I am " + name + "!");
Console.WriteLine("miaomiao");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 委托
{
delegate void AnimalPlay(string name);//委托 格式必须与要委托的函数相似
class Program
{
static void RunCircus(AnimalPlay animalPlay,string name)//函数做参数
{
animalPlay(name);
}
static void Main(string[] args)
{
AnimalPlay animalPlay = new AnimalPlay(DogAct);//指定委托哪个函数
RunCircus(animalPlay, "dawa");//执行函数
}
static void DogAct(string name )
{
Console.WriteLine("hello,I am " + name + "!");
Console.WriteLine("wangwangwang");
}
static void CatAct(string name)
{
Console.WriteLine("hello,I am " + name + "!");
Console.WriteLine("miaomiao");
}
}
}