Esempio n. 1
0
 public void BoilWater()
 {
     for (int i = 0; i <= 100; i++)
     {
         temperature = i;
         if (temperature > 95)
         {
             BoilEvent?.Invoke(temperature); // 触发事件
         }
     }
 }
Esempio n. 2
0
 public void BoilWater()
 {
     for (int i = 0; i <= 100; i++)
     {
         temperature = i;
         if (temperature > 95)
         {
             // 调用所有注册对象的方法
             BoilEvent?.Invoke(temperature);
         }
     }
 }
Esempio n. 3
0
        public void BoilWater()
        {
            for (int i = 0; i < 100; i++)
            {
                temperature = i;
            }

            if (temperature >= 96)
            {
                BoildEventArgs e = new BoildEventArgs(temperature);
                BoilEvent?.Invoke(this, e);
            }
        }
Esempio n. 4
0
        public event BoilHandler BoilEvent;             //声明事件

        /// <summary>
        /// 烧水
        /// </summary>
        public void BoilWater()
        {
            for (int i = 0; i <= 100; i++)
            {
                temperature = i;

                //if (temperature > 95)
                //{
                //    if (BoilEvent != null)
                //    { //如果有对象注册
                //        BoilEvent(temperature);  //调用所有注册对象的方法
                //    }
                //}

                BoilEvent?.Invoke(temperature);  //调用所有注册对象的方法
            }
        }