May 2010
Intermediate to advanced
1752 pages
41h 17m
English
Clearly, the previous SimpleDelegate example was intended to be purely illustrative in nature, given that there would be no compelling reason to define a delegate simply to add two numbers! To provide a more realistic use of delegate types, let's use delegates to define a Car class that has the ability to inform external entities about its current engine state. To do so, we will take the following steps:
Define a new delegate type that will send notifications to the caller.
Declare a member variable of this delegate in the Car class.
Create a helper function on the Car that allows the caller to specify the method to call back to.
Implement the Accelerate() method to invoke the delegate's ...