task13.cs 575 B

12345678910111213141516171819202122
  1. //13
  2. string[] Dates = { "19.06.1999", "16.03.2003", "29.10.2007", "16.03.2021", "12.03.2007" };
  3. Dictionary<string, int> month1 = new Dictionary<string, int>();
  4. foreach (var date in Dates)
  5. {
  6. DateTime date1 = DateTime.ParseExact(date, "dd.MM.yyyy", null);
  7. string month = date1.ToString("MMMM");
  8. if (month1.ContainsKey(month))
  9. {
  10. month1[month]++;
  11. }
  12. else
  13. {
  14. month1.Add(month, 1);
  15. }
  16. }
  17. var popul = month1.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
  18. Console.WriteLine("Самый популярный месяц: " + popul);