Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Отчёт_о_вооружении
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Army army = new Army();
- army.Work();
- }
- }
- class Army
- {
- private List<Soldier> _platoon = new List<Soldier>();
- public Army()
- {
- _platoon.Add(new Soldier("Джек", "Пулемет", "Рядовой", 6));
- _platoon.Add(new Soldier("Джон", "Автомат", "Сержант", 24));
- _platoon.Add(new Soldier("Стив", "Снайпер", "Мл. Сержант", 18));
- _platoon.Add(new Soldier("Пол", "Автомат", "Рядовой", 12));
- _platoon.Add(new Soldier("Майкл", "Автомат", "Рядовой", 2));
- _platoon.Add(new Soldier("Питер", "Автомат", "Рядовой", 16));
- }
- public void Work()
- {
- Console.WriteLine("Полный состав взвода:");
- ShowPlatoon();
- Console.WriteLine("\nОтсортированный состав:");
- MilitaryPersonRequest();
- }
- private void MilitaryPersonRequest()
- {
- var filteredSoldiers = from Soldier soldier in _platoon select new { name = soldier.Name, rank = soldier.Rank };
- foreach (var soldier in filteredSoldiers)
- {
- Console.WriteLine(soldier.name + " " + soldier.rank);
- }
- }
- private void ShowPlatoon()
- {
- foreach (var soldier in _platoon)
- {
- soldier.ShowDescription();
- }
- }
- }
- class Soldier
- {
- public Soldier(string name, string weapon, string rank, int militaryService)
- {
- Name = name;
- Weapon = weapon;
- Rank = rank;
- MilitaryService = militaryService;
- }
- public string Name { get; private set; }
- public string Weapon { get; private set; }
- public string Rank { get; private set; }
- public int MilitaryService { get; private set; }
- public void ShowDescription()
- {
- Console.WriteLine($"Имя: {Name} Вооружение: {Weapon} Звание: {Rank} Срок службы: {MilitaryService}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement