Saturday, November 19, 2016

Brain Teaser - Delegates

In this post, I will be showing how we can further optimise the code from previous post by replacing Generics with Delegate.
  • Define two delegates in Car class one for method Move() and another for method ApplyBreak() and invoke both of them inside Drive method as shown below.

  • Make classes Benz and Audi use Car class as shown below.       



   
  • Now make use of the above classes and see the output

            

No comments:

Post a Comment