using System;
using System.Collections.Generic;
using System.Text;
namespace ClassInherit
{
class Temperature
{
int _TemperaturePipe;
public int TemperaturePipe
{
get
{
return _TemperaturePipe;
}
set
{
_TemperaturePipe = value;
CheckTemperature(TemperaturePipe);
}
}
public Temperature(int t)
{
TemperaturePipe = t;
CheckTemperature(TemperaturePipe);
}
void CheckTemperature(int t)
{
if (TemperaturePipe > 45 || TemperaturePipe < 10)
{
throw new Exception("温度异常!当前温度" + TemperaturePipe.ToString() + "摄氏度。");
}
}
}
class run
{
static void Main()
{
Temperature t = new Temperature(18);
Random rnd = new Random(DateTime.Now.Millisecond);
for (; ; )
{
for (int tim = 0; tim < 33554432; tim++) { } //延时,没有任何意义。
try
{
t.TemperaturePipe = rnd.Next(5, 50);
Console.SetCursorPosition(3, 2);
Console.Write("温度" + t.TemperaturePipe.ToString() + "摄氏度正常! ");
}
catch (Exception e)
{ //异常引发!
Console.SetCursorPosition(5, 4);
Console.Write(e.Message + " ");
}
}
}
}
}
浙公网安备 33010602011771号