您的位置:首页 > 编程语言 > C#

c#中的委托使用(方法的调用, 和类的实话)

2015-02-08 23:31 274 查看
方法的调用
delegate int test1(int a);
class Program
{

static int num = 10;
static void Main(string[] args)
{
test1 t = new test1(max);
t(40);
Console.WriteLine("max,{0}", num);
Console.ReadLine();
}
public static int max(int a)
{
num += a;
return num;
}
}


类额实例化

class  weituo {
public   int num = 10;
//非静态
public  int max(int a)
{
num += a;
return num;
}

}

Main ()
{
weituo wt = new weituo();
test1 t1 = new test1(wt.max);
t1(50);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: