// Register event handlers as anonymous methods.
c1.AboutToBlow += delegate
{
aboutToBlowCounter++;
Console.WriteLine("Eek! Going too fast!");
};
c1.AboutToBlow += delegate(string msg)
{
aboutToBlowCounter++;
Console.WriteLine("Critical Message from Car: {0}", msg);
};
...
Console.WriteLine("AboutToBlow event was fired {0} times.",
aboutToBlowCounter);
Console.ReadLine();
}
Once you run this updated Main() method, you will find the final Console.WriteLine() reports
the AboutToBlow event was fired twice.
Do'stlaringiz bilan baham: