· 7 years ago · May 19, 2018, 07:44 AM
1public class Foo1
2{
3
4 public static void Run()
5 {
6
7 var clients = GetClients();
8
9 Console.WriteLine($"Ðайдено {clients.Count} клиентов. Ðктивных {clients.Where(e => e.IsActive).Count()}, неактивных {clients.Where(e => !e.IsActive).Count()}");
10
11 var appropriateClients = new List<Client>();
12
13 foreach (var client in clients)
14 {
15
16 if (!IsAppropriateEmail(client) || !client.IsActive)
17 continue;
18
19 appropriateClients.Add(client);
20 }
21 Console.WriteLine($"Ðайдено {appropriateClients.Count}");
22
23 Console.ReadLine();
24 }
25
26
27 private static bool IsAppropriateEmail(Client client)
28 {
29 return client.Email.EndsWith(".ru");
30 }
31
32 private static List<Client> GetClients()
33 {
34
35 //TODO: получать данных из БД
36
37 var result = new List<Client>();
38 List<string> domains = new List<string>
39 {
40 "yandex.ru",
41 "gmail.com",
42 "mail.ru",
43 "yandex.ua",
44 "yandex.kz"
45 };
46
47 for (int i = 1; i <= 10000000; i++)
48 {
49
50 var client = new Client
51 {
52
53 Name = "клиент " + i,
54
55 IsActive = i % 2 == 0 || i % 5 == 0
56
57 };
58
59
60 string domain = domains[0];
61
62 if (i % 11 == 0)
63 domain = domains[4];
64 else if (i % 9 == 0)
65 domain = domains[3];
66 else if (i % 5 == 0)
67 domain = domains[2];
68 else if (i % 3 == 0)
69 domain = domains[1];
70
71
72 client.Email = $"client{i}@{domain}";
73
74 result.Add(client);
75
76 }
77
78 return result;
79
80 }
81
82
83 public class Client
84 {
85
86 public string Name { get; set; }
87
88
89 public string Email { get; set; }
90
91
92 public bool IsActive { get; set; }
93
94 }
95
96}