zoukankan      html  css  js  c++  java
  • 简单的猫叫,老鼠跑,主人醒

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace DelegateEvent
    {
        public delegate void CatEventHandler(object sender, EventArgs e);
        public class Cat
        {
            public event CatEventHandler CatEvent;
            public void Scream(EventArgs e)
            {
                if (CatEvent != null) //有没有订阅
                {
                    Console.WriteLine("猫叫……");
                    CatEvent(this, e);
                }
            }
            public void Mouse(object sender,EventArgs e)
            {
                Console.WriteLine("老鼠跑……");
            }
            public void People(object sender, EventArgs e)
            {
                Console.WriteLine("主人醒……");
            }
            static void Main()
            {
                Cat cat = new Cat();
                cat.CatEvent += new CatEventHandler(cat.Mouse);
                cat.CatEvent += new CatEventHandler(cat.People);
                cat.Scream(EventArgs.Empty);
                Console.Read();
            }
        }

    }

  • 相关阅读:
    CSS3阴影 box-shadow的使用和技巧总结
    事件
    表单操作
    DOM
    BOM
    js总结1
    css3
    css图片文字相关属性
    CSS盒子模型及布局
    写博客的几个注意事项
  • 原文地址:https://www.cnblogs.com/lhking/p/1390554.html
Copyright © 2011-2022 走看看