Chapter 9: Delegating Those Important Events

In This Chapter

check.png Using delegates to solve the callback problem

check.png Using delegates to customize a method

check.png Implementing delegates by using anonymous methods

check.png Using C# events to notify the world when interesting events happen

This chapter looks into a corner of C# that has been around since the birth of the language, but one that I’ve avoided because it’s challenging stuff. However, if you can bear with me — and I try to go as easy on you as possible — the payoff is well worth it.

E.T., Phone Home — the Callback Problem

If you’ve seen the Steven Spielberg movie E.T., the Extraterrestrial (1982), you watched the cute but ugly little alien stranded on Earth try to build an apparatus from old toy parts with which he could “phone home.” He needed his ship to pick him up.

It’s a big jump from E.T. to C#, but code sometimes needs to phone home, too. For example, you may have wondered how the Windows progress bar works. It’s the horizontal “bar” that gradually fills up with coloring to show progress during a lengthy operation, such as copying files. ...

Get C# 5.0 All-in-One For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.