예제 #1
0
 public static void LapStop()
 {
     if (!_running)
     {
         StopWatchException.NotStartedException();
     }
     _laps++;
     _lapTimes.Add(DateTime.Now);
 }
예제 #2
0
 public static void Stop()
 {
     if (!_running)
     {
         StopWatchException.NotStartedException();
     }
     _stop    = DateTime.Now;
     _running = false;
 }
예제 #3
0
 public static void Start()
 {
     if (_running)
     {
         StopWatchException.AlreadyStartedException();
     }
     _start   = DateTime.Now;
     _running = true;
 }
예제 #4
0
 public static TimeSpan GetDuration()
 {
     if (_running)
     {
         StopWatchException.NotStoppedExeption();
     }
     if (_start == _stop)
     {
         StopWatchException.NotStartedException();
     }
     return(_stop - _start);
 }
예제 #5
0
 public static void DisplayAll()
 {
     if (_running)
     {
         StopWatchException.NotStoppedExeption();
     }
     Console.WriteLine("-----------------------------------");
     Console.WriteLine($"started: {_start}");
     for (int i = 0; i < _lapTimes.Count; i++)
     {
         Console.WriteLine($"lap {i + 1}: {_lapTimes[i]}");
     }
     Console.WriteLine($"stopped: {_stop}");
     Console.WriteLine($"full duration was: {GetDuration()}");
     Console.WriteLine("-----------------------------------");
 }