来一发 委托C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace no1
{
delegate int numberChanger(int n);
class Program
{
static int num = 20;
static void Main(string[] args)
{
//woman w = new woman();
//man m = new man();
//w.cleanRoom();
//m.cleanRoom();
//Console.Read();
numberChanger nc1 = new numberChanger(addNum);//通过委托调用静态方法
nc1(10);
Console.WriteLine("value of Num:{0}",num);
Myclass c = new Myclass();
numberChanger nc2 = new numberChanger(c.mutiply);//通过委托吃调用实例化方法
nc2(22);
Console.WriteLine("第二:{0}", c.num2);
Console.ReadLine();
}
public static int addNum(int a)
{
num += a;
return num;
}
}
class Myclass
{
public int num2 = 35;
public int mutiply(int p)
{
num2 *= p;
return num2;
}
}
}