详细介绍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();
}
}
}