您当前的位置: 首页 >  c#

刘一哥GIS

暂无认证

  • 4浏览

    0关注

    934博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#委托、事件学习之(三)——热水器烧水案例

刘一哥GIS 发布时间:2015-09-14 11:17:59 ,浏览量:4

using System;

namespace DelegateExample
{
    public class Heater
    {
        private int temperature;
        public string type = "RealFire 001"; // 添加型号作为演示
        public string area = "China Xi'an"; // 添加产地作为演示
                                            //声明委托
        public delegate void BoiledEventHandler(Object sender, BoiledEventArgs e);
        public event BoiledEventHandler Boiled; //声明事件
                                                // 定义BoiledEventArgs类,传递给Observer所感兴趣的信息
                                                //继承EventArgs
        public class BoiledEventArgs : EventArgs
        {
            public readonly int temperature;//
            public BoiledEventArgs(int temperature)
            {
                this.temperature = temperature;
            }
        }
        // 可以供继承自 Heater 的类重写,以便继承类拒绝其他对象对它的监视
        protected virtual void OnBoiled(Boil
关注
打赏
1665586602
查看更多评论
立即登录/注册

微信扫码登录

0.0856s