zoukankan      html  css  js  c++  java
  • 看懂 ,学会 .NET 事件的正确姿势-简单版

    using System;
    namespace EventTest
    {
        public class EventDemo
        {
            public void EventTest()
            {
                Cat cat = new Cat();
                MouseEventArgs ms = new MouseEventArgs();
                MasterEventArgs mas = new MasterEventArgs();
                cat.Calling += ms.Escape;//老鼠对 clling 订阅
                cat.Calling += mas.Wakened;//人 对 calling 订阅
                cat.Call(); //猫叫
            }
        }
        public sealed class Cat
        {
            public event EventHandler Calling;
            public void Call()
            {
                Console.WriteLine("猫叫了...");
                Calling?.Invoke(this, EventArgs.Empty);
            }
        }
        public sealed class MouseEventArgs : EventArgs
        {
            public void Escape(object sender, EventArgs e)
            {
                Console.WriteLine("老鼠逃跑了...");
            }
        }
        public sealed class MasterEventArgs : EventArgs
        {
            public void Wakened(object sender, EventArgs e)
            {
                Console.WriteLine("主人醒了");
            }
        }
    }
  • 相关阅读:
    Splay专题总结
    UVa12657
    ZOJ3772
    POJ1743
    高斯消元模板
    python使用chrom登陆微博
    mysql常用数据库(表)命令
    mysql索引
    mysql建表的时候,时间戳的选用
    php 金额每三位添加一个逗号
  • 原文地址:https://www.cnblogs.com/LiMin/p/10364867.html
Copyright © 2011-2022 走看看