task12.cs 633 B

1234567891011121314151617181920212223
  1. //12
  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 date1 = GetNearestDate(Dates);
  14. Console.WriteLine($"Ближайшая дата рождения: {date1:dd.MM.yyyy}");
  15. static DateTime GetNearestDate(List<DateTime> dates)
  16. {
  17. DateTime today = DateTime.Today;
  18. dates.Sort((d1, d2) => Math.Abs((d1 - today).Days).CompareTo(Math.Abs((d2 - today).Days)));
  19. return dates[0];
  20. }