Free mag vol1 | Page 429

CHAPTER 10  DELEGATES, EVENTS, AND LAMBDA EXPRESSIONS public delegate void CarEngineHandler(string msgForCaller); // 2) Define a member variable of this delegate. private CarEngineHandler listOfHandlers; } // 3) Add registration function for the caller. public void RegisterWithCarEngine(CarEngineHandler methodToCall) { listOfHandlers = methodToCall; } Notice in this example that we define the delegate types directly within the scope of the Car class, which is certainly not necessary, but does help enforce the idea that the delegate works naturally with this particular class. Our delegate type, CarEngineHandler, can point to any method taking a single string as