Created
November 14, 2016 08:08
-
-
Save bolenton/fdb97131f9714c101dc20c23eae8ad86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace StopWatch | |
{ | |
public class StopWatch | |
{ | |
private DateTime StartTime { get; set; } | |
public void Start() => this.StartTime = DateTime.Now; | |
public TimeSpan Stop() => DateTime.Now.Subtract(StartTime); | |
} | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
ConsoleKey userChoice; | |
do | |
{ | |
Console.WriteLine("\n\nPress the 'Space' key to Start timer, any other button to exit."); | |
userChoice = Console.ReadKey().Key; | |
if(userChoice != ConsoleKey.Spacebar)break; | |
var watch = new StopWatch(); | |
watch.Start(); | |
Console.WriteLine("\nTimer Started.. press Space to Stop timer, any other button to exit."); | |
userChoice = Console.ReadKey().Key; | |
var duration = watch.Stop(); | |
Console.WriteLine($"\nDuration: {duration.Hours}:{duration.Minutes}:{duration.Seconds}"); | |
} while (userChoice == ConsoleKey.Spacebar); | |
Console.WriteLine("\nExiting timer...."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment