// Now use anonymous methods.
c1.OnAboutToBlow(delegate(string msg) { Console.WriteLine(msg); });
c1.OnExploded(delegate(string msg) { Console.WriteLine(msg); });
// Speed up (this will generate the events.)
Console.WriteLine("\n***** Speeding up *****");
for (int i = 0; i < 6; i++)
c1.SpeedUp(20);
Console.ReadLine();
}
And finally, here is the Main() method now using lambda expressions:
static void Main(string[] args)
{
Console.WriteLine("***** More Fun with Lambdas *****\n");
// Make a car as usual.
Car c1 = new Car("SlugBug", 100, 10);
// Now with lambdas!
c1.OnAboutToBlow(msg => { Console.WriteLine(msg); });
c1.OnExploded(msg => { Console.WriteLine(msg); });
// Speed up (this will generate the events).
Console.WriteLine("\n***** Speeding up *****");
for (int i = 0; i < 6; i++)
c1.SpeedUp(20);
Console.ReadLine();
}
Do'stlaringiz bilan baham: |