namespace CShapExc
{
class Program
{
static void Main()
{
Heater h = new Heater();
JBQ j = new JBQ();
h.BoilEven += j.MakeAlert;
h.BoilEven += j.DisplayInfo;
h.BoilWater();
Console.ReadKey();
}
}
public class Heater
{
private int wenDu;
public delegate void BoilHandle(int para);//声明委托
public event BoilHandle BoilEven;//声明事件
/// <summary>
/// 烧水
/// </summary>
public void BoilWater()
{
for (int i = 0; i <= 110; i++)
{
wenDu = i;
if (wenDu > 95)
{
if (BoilEven != null)//如果有对象注册
{
BoilEven(wenDu);//调用所有注册对象的方法
}
}
}
}
}
/// <summary>
/// 警报器
/// </summary>
public class JBQ
{
/// <summary>
/// 报警
/// </summary>
/// <param name="param"></param>
public void MakeAlert(int param)
{
Console.WriteLine("警报警报:温度已经{0}度了",param);
}
/// <summary>
/// 显示信息
/// </summary>
/// <param name="param"></param>
public void DisplayInfo(int param)
{
Console.WriteLine("当前温度:{0}度",param);
}
}
}