delegate的问题
程序代码:
class A { //问题1:我看好多教程里面说"delegate的定义必须放到任何类的外面",但是我看例子有些在类里面声明,而且运行正确 public delegate void delegateDemo(int number); static void Main() { //问题2:2和4为什么可以省略new delegateDemo myDelegate = new delegateDemo(A.fun1);//1 // delegateDemo myDelegate = fun1;//2 // A a = new A(); // delegateDemo myDelegate = new delegateDemo(a.fun2);//3 // delegateDemo myDelegate = a.fun2;//4 } //静态方法 private static void fun1(int number) { ... } //实例方法 private void fun2(int number) { ... } }
最近学C#遇到的问题比较多,分少,望见谅