事件,继承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();
        }




    }
}

  

posted @ 2017-11-08 09:44  公众号python学习开发  阅读(211)  评论(0编辑  收藏  举报