O'Reilly logo

Pro C# 2010 and the .NET 4 Platform, Fifth Edition by Andrew Troelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.6. Method Group Conversion Syntax

In the previous CarDelegate example, we explicitly created instances of the Car.CarEngineHandler delegate object in order to register and unregister with the engine notifications:

static void Main(string[] args)
{
  Console.WriteLine("***** Delegates as event enablers *****\n");

  Car c1 = new Car("SlugBug", 100, 10);
  c1.RegisterWithCarEngine(new Car.CarEngineHandler(OnCarEngineEvent));

  Car.CarEngineHandler handler2 =
new Car.CarEngineHandler(OnCarEngineEvent2);
  c1.RegisterWithCarEngine(handler2);
...
}

To be sure, if you need to call any of the inherited members of MulticastDelegate or Delegate, manually creating a delegate variable is the most straightforward way of doing so. However, in most cases, you don't ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required