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