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 | List<Player> players = new List<Player>(); | |
12 | for (int i = 0; i < 10; i++) | |
13 | { | |
14 | players.Add(new Player()); | |
15 | } | |
16 | ||
17 | List<Player> sortList = players.OrderByDescending(player => player.Level).Take(3).ToList<Player>(); | |
18 | Console.WriteLine("Вывод топ 3-х игроков по уровню"); | |
19 | foreach (var player in sortList) | |
20 | { | |
21 | Console.WriteLine(player.GetInfo()); | |
22 | } | |
23 | ||
24 | sortList = players.OrderByDescending(player => player.Force).Take(3).ToList<Player>(); | |
25 | Console.WriteLine("\n\nВывод топ 3-х игроков по силе"); | |
26 | foreach (var player in sortList) | |
27 | { | |
28 | Console.WriteLine(player.GetInfo()); | |
29 | } | |
30 | Console.ReadKey(); | |
31 | } | |
32 | } | |
33 | public static class RandomStatic | |
34 | { | |
35 | static private Random _rand = new Random(); | |
36 | static public int GetNext(int min, int max) | |
37 | { | |
38 | return _rand.Next(min, max); | |
39 | } | |
40 | } | |
41 | public class Player | |
42 | { | |
43 | public string Name { get; private set; } | |
44 | public int Level { get; private set; } | |
45 | public int Force { get; private set; } | |
46 | public Player() | |
47 | { | |
48 | Name = GeneratorName.CreateName(); | |
49 | Level = RandomStatic.GetNext(0, 100); | |
50 | Force = RandomStatic.GetNext(0, 50); | |
51 | } | |
52 | public string GetInfo() | |
53 | { | |
54 | return $"{Name} - Lvl: {Level} - Сила: {Force}"; | |
55 | } | |
56 | } | |
57 | public static class GeneratorName | |
58 | { | |
59 | public static string CreateName() | |
60 | { | |
61 | string result = ""; | |
62 | int length = RandomStatic.GetNext(3, 10); | |
63 | for (int i = 0; i < length; i++) | |
64 | { | |
65 | result += (char)RandomStatic.GetNext('A', 'Z' + 1); | |
66 | } | |
67 | return result; | |
68 | } | |
69 | } | |
70 | } |