예제 #1
0
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            while (true)
            {
                Console.WriteLine("\nPress 1 to \"start\" the stop watch");
                Console.WriteLine("Press 2 to \"stop\" the stop watch");
                Console.Write("Type here: ");

                try
                {
                    var input = Convert.ToInt32(Console.ReadLine());

                    if (input == 1)
                    {
                        stopWatch.Start();
                    }
                    else if (input == 2)
                    {
                        stopWatch.Stop();
                        Console.WriteLine("Duration: {0}", stopWatch.Calculate());
                    }
                    else
                    {
                        Console.WriteLine("Invalid input! Try again!");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Invalid input! Try again!");
                    continue;
                }
            }
        }