委托方法:
public delegate void MethodlDeleage();
class Program
{
//int n = 10;
//Person p1 = new Person();
//委托也是一种数据类型;使用时需要new一个对象,关键自是Delegate;
Leader(M1);
Console.ReadKey();
}
static void Leader(MethodlDeleage lastMethod)
{
lastMethod();
}
static void M1()
{
Console.WriteLine("这是M1");
}
static void M2()
{
Console.WriteLine("这是M2");
}
}
public delegate void MethodlDeleage();
class Program
{
static void Main(string[] args){
//int n = 10;
//Person p1 = new Person();
//委托也是一种数据类型;使用时需要new一个对象,关键自是Delegate;
Leader(M1);
Console.ReadKey();
}
static void Leader(MethodlDeleage lastMethod)
{
lastMethod();
}
static void M1()
{
Console.WriteLine("这是M1");
}
static void M2()
{
Console.WriteLine("这是M2");
}
}