SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | - | namespace C_sharp_Light |
3 | + | using System.Linq; |
4 | ||
5 | namespace LinqTrain | |
6 | { | |
7 | - | static void Main(string[] args) |
7 | + | |
8 | { | |
9 | - | |
9 | + | public static void Main() |
10 | { | |
11 | bool isOpen = true; | |
12 | while (isOpen) | |
13 | { | |
14 | List<Criminal> criminals = new List<Criminal>(); | |
15 | for (int i = 0; i < 80; i++) | |
16 | { | |
17 | criminals.Add(new Criminal()); | |
18 | Console.WriteLine($"{i}: {criminals[i].GetInfo()}"); | |
19 | } | |
20 | ||
21 | Console.ReadKey(true); | |
22 | Console.Clear(); | |
23 | ||
24 | int height, weight; | |
25 | string nationality; | |
26 | Console.Write("Введите минимальный рост: "); | |
27 | height = Convert.ToInt32(Console.ReadLine()); | |
28 | Console.Write("Введите минимальный вес: "); | |
29 | weight = Convert.ToInt32(Console.ReadLine()); | |
30 | Console.Write("Введите Национальность: "); | |
31 | nationality = Console.ReadLine(); | |
32 | ||
33 | var filltedList = from Criminal crim in criminals | |
34 | where crim.Height >= height | |
35 | where crim.Weight >= weight | |
36 | where crim.Nationality.ToLower() == nationality.ToLower() | |
37 | where crim.IsJail == false | |
38 | select crim; | |
39 | ||
40 | Console.Clear(); | |
41 | int count = 0; | |
42 | foreach (var item in filltedList) | |
43 | { | |
44 | Console.WriteLine($"{count}: {item.GetInfo()}"); | |
45 | count++; | |
46 | } | |
47 | if (Console.ReadKey().Key == ConsoleKey.Escape) | |
48 | isOpen = false; | |
49 | } | |
50 | } | |
51 | } | |
52 | public static class RandomStatic | |
53 | { | |
54 | static private Random _rand = new Random(); | |
55 | static public int GetNext(int min, int max) | |
56 | { | |
57 | return _rand.Next(min, max); | |
58 | } | |
59 | } | |
60 | class FullName | |
61 | { | |
62 | public string Name { get; private set; } | |
63 | public string Surname { get; private set; } | |
64 | public string MiddleName { get; private set; } | |
65 | public FullName() | |
66 | { | |
67 | Name = new string[] { "Август", "Богдан", "Ваня", "Георгий", "Данил", "Женя" }[RandomStatic.GetNext(0, 6)]; | |
68 | Surname = new string[] { "ЛУчников", "Захарчев", "Зайцев", "КУзнецов", "Столяров", "Коробничиков" }[RandomStatic.GetNext(0, 6)]; | |
69 | MiddleName = new string[] { "Сергеевич", "Андреевич", "Саавич", "Арсеневич" }[RandomStatic.GetNext(0, 4)]; | |
70 | } | |
71 | } | |
72 | class Criminal | |
73 | { | |
74 | public FullName FullName { get; private set; } | |
75 | public string Nationality { get; private set; } | |
76 | public int Height { get; private set; } | |
77 | public int Weight { get; private set; } | |
78 | public bool IsJail { get; private set; } | |
79 | public Criminal() | |
80 | { | |
81 | FullName = new FullName(); | |
82 | IsJail = Convert.ToBoolean(RandomStatic.GetNext(0, 2)); | |
83 | Height = RandomStatic.GetNext(140, 200); | |
84 | Weight = RandomStatic.GetNext(40, 120); | |
85 | Nationality = new string[] { "Бразилец", "Канадец", "Мексиканец", "Португалец", "Француз" }[RandomStatic.GetNext(0, 5)]; | |
86 | } | |
87 | public string GetInfo() | |
88 | { | |
89 | return $"{FullName.Surname} {FullName.Name} {FullName.MiddleName}- {Nationality}. Рост - {Height}. Вес - {Weight}. Заключен - {IsJail}"; | |
90 | } | |
91 | } | |
92 | } |