Advertisement
TwinFrame

LINQ_MergeTwoArmy

Dec 19th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Clight_44_LINQ_MergeTwoArmy
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> fio = new List<string> { "Иванов А.Г.", "Владимиров Б.У.", "Боксанин Г.В." , "Генацвали А.В." ,
  12. "Маринин С.А.", "Бигорян Х.А.", "Бевгенов С.М.", "Мариуполев С.В", "Надеждина Н.Т.", "Русланков В.А.",
  13. "Сергеев Н.Н.", "Бирмин И.П.", "Баринок Ж.А.", "Игрил Х.Х.", "Боксигенов П.С.", "Возбудидзе А.Ю.",
  14. "Попин М.Ю.", "Сааркян С.И." };
  15.  
  16. List<Soldier> team1 = CreateTeam(fio, 7);
  17. List<Soldier> team2 = CreateTeam(fio, 7);
  18.  
  19. team2 = team1.Where(soldier => soldier.Fio.StartsWith("Б")).Union(team2).ToList();
  20.  
  21. foreach (var soldier in team2)
  22. {
  23. soldier.ShowInfo();
  24. }
  25.  
  26. Console.ReadKey();
  27. }
  28.  
  29. public static List<Soldier> CreateTeam(List<string> fio, int soldiersCount)
  30. {
  31. Random random = new Random();
  32.  
  33. List<Soldier> tempSoldiers = new List<Soldier> { };
  34.  
  35. for (int i = 0; i < soldiersCount; i++)
  36. {
  37. int tempNumber = random.Next(0, fio.Count);
  38. Soldier tempSoldier = new Soldier(fio[tempNumber]);
  39. tempSoldiers.Add(tempSoldier);
  40. }
  41.  
  42. return tempSoldiers;
  43. }
  44. }
  45.  
  46. class Soldier
  47. {
  48. public string Fio { get; private set; }
  49.  
  50. public Soldier(string fio)
  51. {
  52. Fio = fio;
  53. }
  54.  
  55. public void ShowInfo()
  56. {
  57. Console.WriteLine(Fio);
  58. }
  59.  
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement