using System;
delegate int mydelegate();
class myclass {
public int InstMethod() {
Console.WriteLine("Call the InstMethod.");
return 0;
}
}
class Test
{
static public void Main()
{
myclass p=new myclass();
mydelegate d=new mydelegate(p.InstMethod);
d(); //指代p.InstMethod
}
}
结果是:Call the InstMethod.
这句话是哪条语句输出的.程序之间有什么关系,在此谢过.
delegate int mydelegate();
class myclass {
public int InstMethod() {
Console.WriteLine("Call the InstMethod.");
return 0;
}
}
class Test
{
static public void Main()
{
myclass p=new myclass();
mydelegate d=new mydelegate(p.InstMethod);
d(); //指代p.InstMethod
}
}
结果是:Call the InstMethod.
这句话是哪条语句输出的.程序之间有什么关系,在此谢过.
delegate int mydelegate(); //定义一个代理,其实是一类方法的模式
class myclass { //定义一个类,类里包括了跟代理同签名的方法,返回值和参数相同
public int InstMethod() {
Console.WriteLine("Call the InstMethod.");
return 0;
}
}
class Test
{
static public void Main()
{
myclass p=new myclass();
mydelegate d=new mydelegate(p.InstMethod); //这个将调用p.InstMethod方法
d(); //指代p.InstMethod 这里就是他具体方法的代码,其实就是那句输出了。
}
}
===没什么意思,只是个返回语句而已....ziluolan1642() ( )
已经给你解诗得很清楚了....
程序也可以改成
delegate void mydelegate();
class myclass
{
public void InstMethod()
{
Console.WriteLine("Call the InstMethod.");
}
}