• 自定义事件


    public partial class event_test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TestEvent te = new TestEvent();
            te.TestPrint += new EventHandler(te_TestPrint);
            te.Testp("10", null);
            TestEvent2 te2 = new TestEvent2();
            te2.Mt += new Mytestevent(te2_Mt);
            te2.Testp("o", new NewEvent() { id="01",name="静"});
        }

        void te2_Mt(NewEvent nevent, object sender)
        {
            Response.Write(nevent.id + nevent.name);
        }

        void te_TestPrint(object sender, EventArgs e)
        {
            Response.Write("0");
        }
    }
    public class TestEvent
    {
        object obj = new object();
        public TestEvent()
        { }
        private event EventHandler testprint;
        public event EventHandler TestPrint
        {
            add
            {
                testprint += value;
            }
            remove
            {
                testprint -= value;
            }
        }
        public void Testp(object sender, EventArgs e)
        {
            testprint(sender, e);
        }
    }

    public class NewEvent : EventArgs
    {
        public string name { get; set; }
        public string id { get; set; }
    }
    public delegate void Mytestevent(NewEvent nevent, object sender);
    public class TestEvent2
    {
        object obj = new object();
        private event Mytestevent mt;
        public event Mytestevent Mt
        {
            add
            {
                mt += value;
            }
            remove
            {
                mt -= value;
            }
        }
        public void Testp(object sender, NewEvent e)
        {
            mt(e, sender);
        }
    }

  • 相关阅读:
    Asp.Net+Oracle+BootStrap+Jquery
    UML类图几种关系的总结
    PHP对象在内存堆栈中的分配
    php sprintf 详解
    微信错误代码45047:客服消息只能发送20条/个用户
    php利用array_search与array_column实现二维数组查找
    mvc 详解
    php中++i 与 i++ 的区分详解
    Git 别名多个命令 超实用
    php 对象继承
  • 原文地址:https://www.cnblogs.com/qiejinxing/p/1572605.html
Copyright © 2020-2023  润新知