Using Delegates

To realize our countdown mechanism in code, let’s build a CountDown class that gets initialized with the number of seconds to countdown. This part leads to the following obvious skeleton code:

image

Next, we need to separate two concerns: the parts dealing with interactive user actions versus the ones that have a reactive nature. We already know how to realize interactive concepts by means of regular methods. In fact, we did so for the timer’s initialization by the definition of a constructor (the method to be called to create a countdown). Besides this, we need a method to start the countdown:

Ignore the “to do” notes for the time ...

Get C# 4.0 Unleashed 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.