Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Clight_44_LINQ_MergeTwoArmy
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> fio = new List<string> { "Иванов А.Г.", "Владимиров Б.У.", "Боксанин Г.В." , "Генацвали А.В." ,
- "Маринин С.А.", "Бигорян Х.А.", "Бевгенов С.М.", "Мариуполев С.В", "Надеждина Н.Т.", "Русланков В.А.",
- "Сергеев Н.Н.", "Бирмин И.П.", "Баринок Ж.А.", "Игрил Х.Х.", "Боксигенов П.С.", "Возбудидзе А.Ю.",
- "Попин М.Ю.", "Сааркян С.И." };
- List<Soldier> team1 = CreateTeam(fio, 7);
- List<Soldier> team2 = CreateTeam(fio, 7);
- team2 = team1.Where(soldier => soldier.Fio.StartsWith("Б")).Union(team2).ToList();
- foreach (var soldier in team2)
- {
- soldier.ShowInfo();
- }
- Console.ReadKey();
- }
- public static List<Soldier> CreateTeam(List<string> fio, int soldiersCount)
- {
- Random random = new Random();
- List<Soldier> tempSoldiers = new List<Soldier> { };
- for (int i = 0; i < soldiersCount; i++)
- {
- int tempNumber = random.Next(0, fio.Count);
- Soldier tempSoldier = new Soldier(fio[tempNumber]);
- tempSoldiers.Add(tempSoldier);
- }
- return tempSoldiers;
- }
- }
- class Soldier
- {
- public string Fio { get; private set; }
- public Soldier(string fio)
- {
- Fio = fio;
- }
- public void ShowInfo()
- {
- Console.WriteLine(Fio);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement