zoukankan      html  css  js  c++  java
  • 委托 事件 observer

    详细介绍http://www.cnblogs.com/jcz1206/articles/2730793.html  ---摘录别人的

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

    namespace StudyConsoleApplication
    {
    public class Heater1
    {
    public delegate void BEventHandler(Object o,BEventArgs b);
    public event BEventHandler B;
    //public int temprature;

    public class BEventArgs : EventArgs
    {
    public readonly int temperature;
    public BEventArgs(int i)
    {
    this.temperature = i;
    }
    }

    public void Water()
    {
    for (int i = 95; i < 100;i++ )
    {
    if (i > 95)
    {
    // temprature = i;
    BEventArgs e = new BEventArgs(i);
    if (B != null)
    {
    B(this,e);
    }
    }
    }
    }

    }
    public class Alar
    {
    public void alarm(Object sender,Heater1.BEventArgs e)
    {
    Console.WriteLine("alarm:didi,水已经{0}度了",e.temperature);
    Console.WriteLine();
    }
    }
    public class Show
    {
    public void show(Object sender,Heater1.BEventArgs e)
    {
    Console.WriteLine("show:水烧开了,当前温度:{0}度.", e.temperature);
    Console.WriteLine();
    }
    }
    }

  • 相关阅读:
    64最长和谐子序列(594)
    63找到字符串中所有字母异位词(438)
    62有效的数独(36)
    10.10
    9.27作业
    9.27
    9.26
    9.25
    9.18学习内容
    9.17作业
  • 原文地址:https://www.cnblogs.com/jcz1206/p/3492344.html
Copyright © 2011-2022 走看看