两个类:热水器类hot 主函数类
class Hot
{
public int water = 0;//水温度
public void tongdian()
{
Myevent = jiare;
Myevent += view;//如果通电就加热并显示水温度
Myevent();
}
private void jiare()
{
this.water += 95;//加热到95
}
private void view()//显示器
{
Console.WriteLine("水的温度是:{0},水已经烧开!",this.water);
}
public event Action Myevent;
}
class Program
{
static void Main(string[] args)
{
Hot a = new Hot();
Console.WriteLine("当前水温度是:"+a.water);
Console.WriteLine("通电");
a.tongdian();
}
}