c# delegate中的一些问题
class Program
{
static void Main(string[] args)
{
var car = new Car(15);
new Alerter(car); \\这个是什么意思呢
car.Run(120);
}
}
class Car
{
public delegate void Notify(int value);
public event Notify notifier;
private int petrol = 0;
public int Petrol
{
get { return petrol; }
set
{
petrol = value;
if (petrol < 10) //当petrol的值小于10时,出发警报
{
if (notifier != null)
{
notifier.Invoke(Petrol);
}
}
}
}
public Car(int petrol)
{
Petrol = petrol;
}
public void Run(int speed)
{
int distance = 0;
while (Petrol > 0)
{
Thread.Sleep(500);
Petrol--;
distance += speed;
Console.WriteLine("Car is running...