委托 和 事件

委托与事件一般都要联合使用

public class ClassEvent
    {
        public delegate void test_event(string s);
        public event test_event t_event;

        public void show(string s)
        {
            if (t_event != null)
            {
                t_event(s);
            }
        }
    }//end
  ClassEvent classevent = new ClassEvent();
                classevent.t_event += delegate(string s)
                {
                    Console.WriteLine("name2:{0}", s);
                };
                classevent.t_event += classevent_t_event;
                classevent.show("123");
说明:
委托和事件 其实与 Action 和Func 类似,不同之处是,Action 和 Func 在初始化的时候,需要默认带一个委托的函数。
欢迎指正:haizi2014@qq.com
原文地址:https://www.cnblogs.com/hcfan/p/7825651.html