Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Объединение_войск
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Arena arena = new Arena();
- arena.Work();
- }
- }
- class Arena
- {
- private List<Fighter> _fighters1 = new List<Fighter>();
- private List<Fighter> _fighters2 = new List<Fighter>();
- public Arena()
- {
- _fighters1.Add(new Fighter("Иванов"));
- _fighters1.Add(new Fighter("Петров"));
- _fighters1.Add(new Fighter("Борисов"));
- _fighters1.Add(new Fighter("Баранкин"));
- _fighters1.Add(new Fighter("Сидоров"));
- _fighters2.Add(new Fighter("Антонов"));
- _fighters2.Add(new Fighter("Сергеев"));
- }
- public void Work()
- {
- Console.WriteLine("Отряд один:");
- ShowSquad(_fighters1);
- Console.WriteLine("\nОтряд два:");
- ShowSquad(_fighters2);
- UnionTeam();
- ExceptFighters();
- Console.WriteLine("\nНовый отряд два:");
- ShowSquad(_fighters2);
- Console.WriteLine("\nОтряд один:");
- ShowSquad(_fighters1);
- }
- private void UnionTeam()
- {
- char necessaryLetter = 'Б';
- _fighters2 = _fighters2.Union(_fighters1.Where(fighter => fighter.Name.StartsWith(necessaryLetter))).ToList();
- }
- private void ExceptFighters()
- {
- _fighters1 = _fighters1.Except(_fighters2).ToList();
- }
- private void ShowSquad(List<Fighter> fighters)
- {
- foreach (var fighter in fighters)
- {
- Console.WriteLine(fighter.Name);
- }
- }
- }
- class Fighter
- {
- public Fighter(string name)
- {
- Name = name;
- }
- public string Name { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement