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.
这句话是哪条语句输出的.程序之间有什么关系,在此谢过.

解决方案 »

  1.   

    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);   //这个将调用p.InstMethod方法
          d(); //指代p.InstMethod   这里就是他具体方法的代码,其实就是那句输出了。
       } 
    }
      

  2.   

    return 0; 是什么意思.
    ===没什么意思,只是个返回语句而已....ziluolan1642() ( ) 
    已经给你解诗得很清楚了....
      

  3.   

    return 0;没有具体的意义 有时候可以作为检查函数执行是否成功
    程序也可以改成
    delegate void mydelegate();
    class myclass
    {
        public void InstMethod()
        {
            Console.WriteLine("Call the InstMethod.");
        }
    }