zoukankan      html  css  js  c++  java
  • 事件,继承EventArgs带有参数的委托

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        public class Myevents : EventArgs
        {
            public string Message;
            public Myevents(string msg)
            {
                this.Message = msg;
            }
        
        
        }
        public class BossDemo3
        {
            public delegate void BossDelegete(object e,Myevents m);
            public event BossDelegete BossEvent;
    
            public void Onmsg(string msg)
            {
                if (BossEvent != null)
                {
    
                    BossEvent(this,new Myevents(msg));
                }
    
            }
            static void Main(string[] args)
            {
    
                BossDemo3 b = new BossDemo3();
                Worker w1 = new Worker("1");
                Worker w2 = new Worker("2");
                b.BossEvent += new BossDelegete(w1.SendMessage);
                b.BossEvent += new BossDelegete(w2.SendMessage);
                b.Onmsg("朋友你好今晚上加班");
                Console.WriteLine("---------------------------");
                Console.ReadKey();
    
    
    
            }
        }
        public class Worker
        {
            private string workerId;
            public Worker(string wi)
            {
                this.workerId = wi;
    
            }
            public void SendMessage(object o,Myevents e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(this.workerId + "卧槽又加班");
                Console.Read();
            }
    
    
    
    
        }
    }
    

      

  • 相关阅读:
    linux 邮件服务器
    Nginx学习之keepalive
    explain 和 desc 详解
    mysql 常用语句
    loop设备及losetup命令
    cryptsetup文件系统加密
    ftp主动与被动模式详解
    大型网站关键技术
    大访问量网站架构设计
    Mysql 的事务隔离级别
  • 原文地址:https://www.cnblogs.com/c-x-a/p/7802493.html
Copyright © 2011-2022 走看看