1234567891011121314151617181920212223 |
- //12
- List<DateTime> Dates = new List<DateTime>
- {
- new DateTime(2011, 09,07),
- new DateTime(2018,03,15),
- new DateTime(2015,05,19),
- new DateTime(2022,07,15),
- new DateTime(2009,02,25),
- new DateTime(2021,09,16),
- new DateTime(2001,06,29),
- new DateTime(2024,03,04)
- };
- DateTime date1 = GetNearestDate(Dates);
- Console.WriteLine($"Ближайшая дата рождения: {date1:dd.MM.yyyy}");
- static DateTime GetNearestDate(List<DateTime> dates)
- {
- DateTime today = DateTime.Today;
- dates.Sort((d1, d2) => Math.Abs((d1 - today).Days).CompareTo(Math.Abs((d2 - today).Days)));
- return dates[0];
- }
|