コード例 #1
0
        static void Main(string[] args)
        {
            var stopWatch = new StopWatch();

            Console.WriteLine("Enter 'start' to start the stopwatch or enter 'stop' to stop the stopwatch!");
            while (true)
            {
                var input = Console.ReadLine().ToLower();
                switch (input)
                {
                case "start":
                    stopWatch.Start();
                    break;

                case "stop":
                    stopWatch.Stop();
                    Console.WriteLine("The time difference between when started and stopped was: {0} minutes and {1} seconds.", stopWatch.Difference.Minutes, stopWatch.Difference.Seconds);
                    break;
                }
            }



            /*Console.WriteLine("press enter to start!");
             *
             * stopWatch.Start();
             * Console.WriteLine("press enter to stop!");
             * ConsoleKeyInfo key = Console.ReadKey();
             * if (Console.ReadKey().Key.ToString() == "Enter")
             * {
             *  stopWatch.Stop();
             * }*/
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var stopwatch = new StopWatch();

            for (var i = 0; i < 2; i++)
            {
                stopwatch.Start();

                Thread.Sleep(1000);

                stopwatch.Stop();

                Console.WriteLine("Duration:" + stopwatch.GetInterval());
                Console.WriteLine("Press Enter to run stopwatch one more time.");
                Console.ReadLine();
            }
        }
コード例 #3
0
ファイル: StopWatch.cs プロジェクト: AAMIR16/coding-practice
        public static void Implementation()
        {
            Console.WriteLine("Enter Start/Stop for stopwatch");
            string input1 = Console.ReadLine();

            if (input1.ToLower() == "start")
            {
                StopWatch.Start();
            }
            //else if (input.ToLower() == "stop")
            //{
            //    StopWatch.Stop();
            //}
            Console.WriteLine("Enter stop to stop");
            string input2 = Console.ReadLine();

            if (input2.ToLower() == "stop")
            {
                StopWatch.Stop();
            }
        }