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