public delegate void MyDel();
    public class myDel
    {
        public static event MyDel catshout;
        public static void ratrun()
        {
            Console.WriteLine("run");
        }
        public static void test()
        {
            catshout += delegate {
                Console.WriteLine(1);
            };
        }
    }
//调用该方法 没有输出"run"
  myDel.test();为什么呢

解决方案 »

  1.   

    我就没看出来为什么要输出"run",甚至都没发现ratrun()这个方法有被调用的地方。
    楼主你知道自己在说什么吗?
      

  2.   

    catshout += delegate...至少订阅事件。事件本身还没有得到触发。
      

  3.   

    catshout += delegate...只是订阅事件
      

  4.   


    public delegate void MyDel();
        public class myDel
        {
            public static event MyDel catshout;
            public static void ratrun()
            {
                Console.WriteLine("run");
            }
            public static void test()
            {
                catshout += new MyDel(ratrun);
            }
        }
    源码应该是这样的。
      

  5.   

    只是将事件挂上了,并没有执行 catshout。需要加上。
    public static void test()
            {
                catshout += delegate {
                    Console.WriteLine(1);
                };
                catshout();
            }
      

  6.   

    catshout 不是事件么 可以当方法用?