task11.cs 664 B

1234567891011121314151617181920212223242526272829
  1. //11
  2. List<DateTime> Dates = new List<DateTime>
  3. {
  4. new DateTime(2011, 09,07),
  5. new DateTime(2018,03,15),
  6. new DateTime(2015,05,19),
  7. new DateTime(2022,07,15),
  8. new DateTime(2009,02,25),
  9. new DateTime(2021,09,16),
  10. new DateTime(2001,06,29),
  11. new DateTime(2024,03,04)
  12. };
  13. DateTime today = DateTime.Today;
  14. DateTime date1 = Dates[0];
  15. TimeSpan date2 = today - date1;
  16. foreach (DateTime date in Dates)
  17. {
  18. TimeSpan difference = today - date;
  19. if (Math.Abs(difference.Days) < Math.Abs(date2.Days))
  20. {
  21. date2 = difference;
  22. date1 = date;
  23. }
  24. }
  25. Console.WriteLine("Ближайшая дата: " + date1.ToShortDateString());