Przeglądaj źródła

добавил класс

kei 5 lat temu
rodzic
commit
eef872c91d
1 zmienionych plików z 26 dodań i 22 usunięć
  1. 26 22
      articles/5_3_1_9_classlib.md

+ 26 - 22
articles/5_3_1_9_classlib.md

@@ -145,32 +145,36 @@ class DateTimeWithCounter
     }
 }
 
-public List<DateTime> PopularMonths(List<DateTime> dates) {
-    // объавляем временный список объектов "ДатаСоСчетчиком"
-    var DateTimeWithCounterList = new List<DateTimeWithCounter>();
-    
-    int PreviousYear = DateTime.Now.Year-1;
-    foreach (DateTime IterDate in dates) {
-        if (IterDate.Year == PreviousYear){
-            // вычисляем начало месяца для текущей даты
-            var DateMonthStart = new DateTime(date.Year, date.Month, 1, 0, 0, 0);
 
-            // ищем эту дату во временном списке
-            var index = DateTimeWithCounterList.FindIndex(item => item.DateTimeProp == DateMonthStart);
-
-            if (index == -1)
-            {
-                // такой даты нет - добавляю
-                DateTimeWithCounterList.
-                    Add(new DateTimeWithCounter(DateMonthStart));
-            }
-            else {
-                // дата есть - увеличиваем счетчик
-                DateTimeWithCounterList[index].Counter++;
+public class Analytics
+{
+    public List<DateTime> PopularMonths(List<DateTime> dates) {
+        // объавляем временный список объектов "ДатаСоСчетчиком"
+        var DateTimeWithCounterList = new List<DateTimeWithCounter>();
+    
+        int PreviousYear = DateTime.Now.Year-1;
+        foreach (DateTime IterDate in dates) {
+            if (IterDate.Year == PreviousYear){
+                // вычисляем начало месяца для текущей даты
+                var DateMonthStart = new DateTime(date.Year, date.Month, 1, 0, 0, 0);
+
+                // ищем эту дату во временном списке
+                var index = DateTimeWithCounterList.FindIndex(item => item.DateTimeProp == DateMonthStart);
+
+                if (index == -1)
+                {
+                    // такой даты нет - добавляю
+                    DateTimeWithCounterList.
+                        Add(new DateTimeWithCounter(DateMonthStart));
+                }
+                else {
+                    // дата есть - увеличиваем счетчик
+                    DateTimeWithCounterList[index].Counter++;
+                }
             }
         }
+        ...
     }
-    ...
 }
 ```