zoukankan      html  css  js  c++  java
  • 事件委托

     //事件和委托实例
       public class Xiaoshou
        {
            public string Mingzi { get; set; }
            public delegate void WaiqinEventHandler(object e, WaiqinEventArgs arg);
            public event WaiqinEventHandler WaiqinHanlder;
            public Xiaoshou(string mingzi)
            {
                Mingzi = mingzi;
            }
            public void WaiqinLa(object e, WaiqinEventArgs arg)
            {
                if (WaiqinHanlder != null)
                {
                    WaiqinHanlder(e, arg);
                }
            }
        }
       public class WaiqinEventArgs : EventArgs {
           public string Msg { get;set;}
           public DateTime EventTime { get; set; }
           public WaiqinEventArgs(string msg) {
               Msg = msg;
               EventTime = DateTime.Now;
           }
       }
       public class KaoqinDandang
       {
           public KaoqinDandang(string name) {
               Console.WriteLine("我是考勤担当;"+name);
           }
           public void Kaoqin(object e, WaiqinEventArgs args)
           {
               Console.WriteLine("考勤担当确认考勤,确认用户:;" + (e as Xiaoshou).Mingzi+"的考勤;");
           }    
        }
       public class boss
       {
           public boss(string name)
           {
               Console.WriteLine("我是老板:" + name);
           }
           public void shenhe(object e, WaiqinEventArgs args)
           {
               Console.WriteLine("老板认可了用户:;" + (e as Xiaoshou).Mingzi + "的外勤;");
           }
       }
       public class program {
           static void main() {
               Xiaoshou xs = new Xiaoshou("小李子");
               KaoqinDandang kd = new KaoqinDandang("小六子");
               boss bs = new boss("大牛子");
               WaiqinEventArgs args=new WaiqinEventArgs("我要外勤");
               
               xs.WaiqinHanlder += new Xiaoshou.WaiqinEventHandler(kd.Kaoqin);
               xs.WaiqinHanlder += new Xiaoshou.WaiqinEventHandler(bs.shenhe);
               xs.WaiqinLa(xs, args);
           }
       }

  • 相关阅读:
    HDU3584 Cube
    SPOJ1029 Matrix Summation
    SPOJ227 Ordering the Soldiers
    ScriptX,smsx打印控件安装及无法打印的问题
    如何做站
    右下角浮动
    简单的显示关闭
    总结
    ubuntu 上网设置
    固定高度后能自动伸缩
  • 原文地址:https://www.cnblogs.com/jeffry/p/5603574.html
Copyright © 2011-2022 走看看