同标题!

解决方案 »

  1.   

    button1.Click += new EventHanndler(btn_click)void btn_click(Object sender,EventArgs e)
    {
        //
    }
      

  2.   

    void foo()
    {
        bar((s, e) => Console.WriteLine("Hello World"));
    }void bar(EventHandler eh)
    {
        eh(this, new EventArgs());
    }
      

  3.   

    老板们真有些吝啬,小弟想看一个完整的且能运行的超简单例子。
    小弟自已做了一个例子,当然是在别人的例子上做了一些修改,请老板们点评using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication3
    {
        class Publisher
        {
            public event EventHandler OnPublish;
            public void Issue(object sender, EventArgs e)
            {
                if (OnPublish != null)
                {
                    Console.WriteLine("发行刊物");
                    OnPublish(sender, e);
                }
            }
        }
        class Subscriber
        {
            public void Receiver(object sender, EventArgs e)
            {
                Console.WriteLine("订阅者已收到了刊物");
            }
        }
        class Program
        {
            static void Main()
            {
                Publisher pub = new Publisher();
                Subscriber zs = new Subscriber();
                pub.OnPublish += new EventHandler(zs.Receiver);
                pub.Issue(pub, new EventArgs());
                Console.Read();
            }
        }  
    }因为微软官方上CSND中没有相关EventHandle的实例,所以做此
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
      class Program  
      {
      static void Main(string[] Args)
      {
        foo();
      }
    static void foo()
    {
        bar((s, e) => Console.WriteLine("Hello World"));
    }static void bar(EventHandler eh)
    {
        eh(this, new EventArgs());
    }
      }
    }这个程序比你的那个简洁。而且我想说明的是,它就是一个普通的委托。不要看到 Event 就觉得必须是事件,必须订阅发布。
      

  5.   

    可惜今晚我还没有读到Lambda表达式,暂时还不明白,但一定会好好研读老板给出的例子 
    至于我的例子的事件执行,一定要按定义发行者,订阅者,订阅事件,触发事件,事件处理程序,其目的更好的理解事件。
      

  6.   

    Lambda表达式 这东西又不是写给程序员用的。学这个东西干嘛。
      

  7.   

    至少csdn可不是“微软官方”啊。
      

  8.   

    基本上所有.net中的控件的事件都使用到了EventHandler,例如可能是其子类。所以一个最简单的例子就是你去拖一个Button控件布局到一个画布上,然后你就看到所谓的“范例”程序注册处理click事件的方法,等等类似的。
      

  9.   

    就委托本身而言,可以这样写var x= new EventHandler(method1);
    x(null,null);这也就可以通过变量x来调用方法method1了。不过这显得很多余了,我们不知道此时为什么要使用EventHandler。
      

  10.   

    http://blog.csdn.net/p2227/article/details/7215585
      

  11.   

    同过看sp1234给出的实例,改进如下using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication3
    {
        class Publisher
        {
            public event EventHandler OnPublish;
            public void Issue()//
            {
                if (OnPublish != null)
                {
                    Console.WriteLine("发行刊物");
                    OnPublish(this, null);
                }
            }
        }
        class Subscriber
        {
            public void Receiver(object sender, EventArgs e)
            {
                Console.WriteLine("订阅者已收到了刊物");
            }
        }
        class Program
        {
            static void Main()
            {
                Publisher pub = new Publisher();
                Subscriber zs = new Subscriber();
                pub.OnPublish += new EventHandler(zs.Receiver);
                pub.Issue();
                Console.Read();
            }
        }  
    }
      

  12.   

    避免线程问题var del=OnPublish
    if (del != null)
      {
      Console.WriteLine("发行刊物");
      del(this, null);
      }