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

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

  • 相关阅读:
    CSS布局设计
    Gulp自动化构建工具的简单使用
    雅虎前端优化的35条军规
    CSS预编译器less简单用法
    java 数据相除
    idea 配置文件中文显示问题
    postgresql 表触发器
    postgresql 自定义函数
    postgresql 自定义聚合函数
    CentOS 6.5 yum安装mysql5.6或其他版本【默认yum只能安装mysql 5.1】 by jason
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1232365.html
Copyright © 2011-2022 走看看