zoukankan      html  css  js  c++  java
  • C#委托事件随笔

     //用户去银行取钱(发布方),用户收到短信提醒,(接收方)
        class Program
        {
            static void Main(string[] args)
            {
                Bank b = new Bank();                      //实例化银行
                User xm = new User("110","1278326@qq.com");         //实例化用户 
                b.send += new Bank.sendEventHandle(xm.ReviceTel);     //注册事件
                b.send += new Bank.sendEventHandle(xm.ReviceEmail);    //注册事件
                b.issure(xm);                           //执行事件
                Console.ReadKey();
            }
        }
    
        public class Bank {
    
            public delegate void sendEventHandle(object o, User xx);  //定义委托
    
            public event sendEventHandle send;              //基于委托的事件
    
            public void issure(User xx) {
                send(this,xx);
            }
        }
    
        public class User:EventArgs{
    
            public string tel;
            public string email;
    
            public User(string telephone, string email)
            {
                this.email = email;
                this.tel = telephone;
            }
    
            public void ReviceTel(object o , User x)
            {
                Console.WriteLine("收到短信"+ x.tel);
    
            }
    
            public void ReviceEmail(object o, User x)
            {
                Console.WriteLine("收到emile" + x.tel);
    
            }
    
        }
  • 相关阅读:
    添加linux alias
    vs2019 switch语句快捷键列出枚举 及常用快捷键
    generic 泛型使用
    华为云 安装centos8.2
    linux 安装redis,mysql,netcore
    react按需加载
    工具类注册基本写法
    vue项目使用深拷贝
    react+less+antd 复习搭建(一)
    python 1 cmd进入工作
  • 原文地址:https://www.cnblogs.com/YorkZhao/p/7800803.html
Copyright © 2011-2022 走看看