fork download
  1. using System;
  2.  
  3. public class Bus
  4. {
  5. protected static readonly DateTime globalStartTime;
  6. protected static readonly int FirstBusNumber;
  7.  
  8. protected int RouteNumber { get; set; }
  9.  
  10.  
  11. static Bus(/*int firstBusNumber*/)//Error if uncomment: The static constructor must be parameterless
  12. {
  13. //FirstBusNumer = firstBusNumber;
  14. globalStartTime = DateTime.Now;
  15.  
  16. Console.WriteLine("The First Bus #{0} starts at global start time {1}",
  17. FirstBusNumber,
  18. globalStartTime.ToLongTimeString());
  19. }
  20.  
  21. public Bus(int routeNum)
  22. {
  23. RouteNumber = routeNum;
  24. Console.WriteLine("Bus #{0} is created.", RouteNumber);
  25. }
  26.  
  27. public void Drive()
  28. {
  29. TimeSpan elapsedTime = DateTime.Now - globalStartTime;
  30. Console.WriteLine("{0} is starting its route {1:N2} minutes after the first Bus #{2}.",
  31. this.RouteNumber,
  32. elapsedTime.TotalMilliseconds,
  33. FirstBusNumber
  34. );
  35. }
  36. }
  37.  
  38. class TestBus
  39. {
  40. static void Main()
  41. {
  42. Bus bus1 = new Bus(71);
  43. Bus bus2 = new Bus(72);
  44. bus1.Drive();
  45. System.Threading.Thread.Sleep(25);
  46. bus2.Drive();
  47. System.Console.WriteLine("Press any key to exit.");
  48. System.Console.ReadKey();
  49. }
  50. }
  51.  
Success #stdin #stdout 0.02s 16056KB
stdin
s
stdout
The First Bus #0 starts at global start time  8:54:56 AM
Bus #71 is created.
Bus #72 is created.
71 is starting its route 10.89 minutes after the first Bus #0.
72 is starting its route 36.28 minutes after the first Bus #0.
Press any key to exit.