• 委托的小例子


    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            a a1 = new a();
            a1.DelegateEvent+=new delegateExample(a1_DelegateEvent);
            a1.A1();

            b b1 = new b();
            b1.myDelegate = new delegateExample(a1_DelegateEvent);
            b1.B1();
        }
        public string a1_DelegateEvent(string Classname)
        {
            return Classname;
        }
    }
    public delegate string delegateExample(string Classname);
    public class a
    {
        public event delegateExample DelegateEvent;
        public string A1()
        {
            if (DelegateEvent != null)
            {
                DelegateEvent("a");
            }
            return "a1";
        }

    }

    public class b
    {
        public delegateExample myDelegate;
        public string B1()
        {
            if (myDelegate != null)
            {
                myDelegate("b");
            }
            return "b1";
        }

    }
    委托是个类,事件是委托的一个实例,存在后是个具体的指针

  • 相关阅读:
    QK对中断的特殊处理
    程序控制的软件复位方法
    软件的按契约设计(DbC---Design by Contract)
    Arduino平台基于DbC的软件调试
    软件测试中的测不准原理
    关于嵌入式软件
    程序设计的SOLID原则
    CPS---(Cyber-Physical Sytem,信息物理融合系统)
    QP之QF原理
    QP之QEP原理
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1232365.html
Copyright © 2020-2023  润新知