• 简单的猫叫,老鼠跑,主人醒


    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();
            }
        }

    }

  • 相关阅读:
    C语言(十八)综合
    C语言(十七)链表
    Redis使用
    fastdb 使用
    CentOS 7.3 安装Oracle 11gR2 64位
    VMWare 12 安装CentOS 7.3 和 Red Hat Enterprise Linux 7.3
    Python学习
    Debian的软件包管理工具命令 (dpkg,apt-get)详解
    Debian8安装Vim8
    VMware12下安装Debian8.5
  • 原文地址:https://www.cnblogs.com/lhking/p/1390554.html
Copyright © 2020-2023  润新知