Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTrain
- {
- class Program
- {
- public static void Main()
- {
- List<Player> players = new List<Player>();
- for (int i = 0; i < 10; i++)
- {
- players.Add(new Player());
- }
- var playerTopListSortedByLevel = players.OrderByDescending(player => player.Level).Take(3);
- Console.WriteLine("Вывод топ 3-х игроков по уровню");
- foreach (var player in playerTopListSortedByLevel)
- {
- Console.WriteLine(player.GetInfo());
- }
- var playerTopListSortedByForce = players.OrderByDescending(player => player.Force).Take(3);
- Console.WriteLine("\n\nВывод топ 3-х игроков по силе");
- foreach (var player in playerTopListSortedByForce)
- {
- Console.WriteLine(player.GetInfo());
- }
- Console.ReadKey();
- }
- }
- public static class RandomStatic
- {
- static private Random _rand = new Random();
- static public int GetNext(int min, int max)
- {
- return _rand.Next(min, max);
- }
- }
- public class Player
- {
- public string Name { get; private set; }
- public int Level { get; private set; }
- public int Force { get; private set; }
- public Player()
- {
- Name = GeneratorName.CreateName();
- Level = RandomStatic.GetNext(0, 100);
- Force = RandomStatic.GetNext(0, 50);
- }
- public string GetInfo()
- {
- return $"{Name} - Lvl: {Level} - Сила: {Force}";
- }
- }
- public static class GeneratorName
- {
- public static string CreateName()
- {
- string result = "";
- int length = RandomStatic.GetNext(3, 10);
- for (int i = 0; i < length; i++)
- {
- result += (char)RandomStatic.GetNext('A', 'Z' + 1);
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement