1234567891011121314151617181920212223242526272829 |
- //11
- 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 today = DateTime.Today;
- DateTime date1 = Dates[0];
- TimeSpan date2 = today - date1;
- foreach (DateTime date in Dates)
- {
- TimeSpan difference = today - date;
- if (Math.Abs(difference.Days) < Math.Abs(date2.Days))
- {
- date2 = difference;
- date1 = date;
- }
- }
- Console.WriteLine("Ближайшая дата: " + date1.ToShortDateString());
|