O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

class CountDown {    private uint _seconds;    public CountDown(uint seconds) {        _seconds = seconds;    }}

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required