· 7 years ago · Aug 30, 2018, 01:40 PM
1 public class Foo1
2 {
3 public static async Task RunAsync()
4 {
5 var clients =await GetClients();
6 int activeCount = 0,inactiveCount=0;
7 foreach (var client in clients)
8 {
9 if (client.IsActive)
10 activeCount++;
11 else
12 inactiveCount++;
13 }
14 Console.WriteLine($"Ðайдено {clients.Count} клиентов. Ðктивных {activeCount}, неактивных {inactiveCount}");
15 var appropriateClients = new List<Client>();
16 foreach (var client in clients)
17 {
18 if(client.IsActive&&IsAppropriateEmail(client))
19 appropriateClients.Add(client);
20 }
21
22 Console.WriteLine($"Ðайдено {appropriateClients.Count}");
23 Console.ReadLine();
24 }
25
26 private static bool IsAppropriateEmail(Client client)
27 {
28 return client.Email.EndsWith(".ru");
29 }
30
31 private static async Task<List<Client>> GetClients()
32 {
33 //TODO: получать данных из БД
34 var result = new List<Client>();
35 for (int i = 1; i <= 10000000; i++)
36 {
37 var client = new Client
38 {
39 Name = "клиент " + i,
40 IsActive = i % 2 == 0 || i % 5 == 0
41 };
42
43 string domain = "yandex.ru";
44 if (i % 3 == 0)
45 {
46 domain = "gmail.com";
47 }
48 else if (i % 5 == 0)
49 {
50 domain = "mail.ru";
51 }
52 else if (i % 9 == 0)
53 {
54 domain = "yandex.ua";
55 }
56 else if (i % 11 == 0)
57 {
58 domain = "yandex.kz";
59 }
60
61 client.Email = $"client{i}@{domain}";
62 result.Add(client);
63 }
64 return result;
65 }
66
67 public class Client
68 {
69 public string Name { get; set; }
70
71 public string Email { get; set; }
72
73 public bool IsActive { get; set; }
74 }
75 }