zoukankan      html  css  js  c++  java
  • 委托的小例子

    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";
        }

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

  • 相关阅读:
    NFS-网络文件共享服务
    CentOS7.5基础优化与常用配置
    29张截图-全新安装CentOS7.5-超详细!
    VMware跨电脑移动Linux虚拟机
    搭建markdown图床-腾讯云COS
    tcpdump-抓包工具-Linux
    vmware克隆虚拟机
    CentOS6.9安装httpd并正确配置静态IP地址
    区块链核心技术与应用
    docker安装jenkins自动化部署
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1232365.html
Copyright © 2011-2022 走看看