是不是delegate?如果是!那么: 相当于指针,或者说实现了指针的功能! 看代码: using System; delegate int TheDelegate(); //声明一个代理 public class TheClass{ public int InstanceMethod(){ Console.Write("Call the instance method"); return 0; } static public int StaticMethod(){ Console.Write("Call the static method."); return 0; } }public class Test{ static public void Main(){ TheClass p = new TheClass; TheClassDelegate d = new TheDelegate(p.InstanceMethod); d(); d = new TheDelegate(TheClass.StaticMethod); d(); } } result: Call the instance of method. Call the static method.
相当于指针,或者说实现了指针的功能!
看代码:
using System;
delegate int TheDelegate(); //声明一个代理
public class TheClass{
public int InstanceMethod(){
Console.Write("Call the instance method");
return 0;
}
static public int StaticMethod(){
Console.Write("Call the static method.");
return 0;
}
}public class Test{
static public void Main(){
TheClass p = new TheClass;
TheClassDelegate d = new TheDelegate(p.InstanceMethod);
d();
d = new TheDelegate(TheClass.StaticMethod);
d();
}
}
result:
Call the instance of method.
Call the static method.