Last active
August 8, 2023 22:49
-
-
Save ShamilAitov/5595b388112ee14b4e5e88945d20b7a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace LINQ2Задание | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Administration administration = new Administration(); | |
administration.PlayProgram(); | |
} | |
} | |
class Administration | |
{ | |
private List<Prisoner> _prisoners = new List<Prisoner>(); | |
public Administration() | |
{ | |
FillPrisoners(); | |
} | |
public void PlayProgram() | |
{ | |
string crime = "Антиправительственное"; | |
Console.WriteLine("Список всех заключенных:"); | |
ShowPrisoners(); | |
var filteredPrisoners = _prisoners.Where(Prisoner => Prisoner.Сrime != crime).ToList(); | |
_prisoners = filteredPrisoners; | |
Console.WriteLine("Список всех заключенных после амнистии:"); | |
ShowPrisoners(); | |
Console.ReadKey(); | |
} | |
private void ShowPrisoners() | |
{ | |
if (_prisoners.Any()) | |
{ | |
foreach (var prisoner in _prisoners) | |
{ | |
prisoner.ShowInfo(); | |
} | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Список пуст!"); | |
} | |
} | |
private void FillPrisoners() | |
{ | |
_prisoners.Add(new Prisoner("Атталь Аберфорт", "Антиправительственное")); | |
_prisoners.Add(new Prisoner("Гарибальди Адриан", "Антиправительственное")); | |
_prisoners.Add(new Prisoner("Макрон Арчибальд", "Правительственное")); | |
_prisoners.Add(new Prisoner("Бардо Бруно", "Антиправительственное")); | |
_prisoners.Add(new Prisoner("Валери Генри", "Правительственное")); | |
_prisoners.Add(new Prisoner("Герарди Киллиан", "Правительственное")); | |
} | |
} | |
class Prisoner | |
{ | |
public Prisoner(string fullName, string crime) | |
{ | |
FullName = fullName; | |
Сrime = crime; | |
} | |
public string FullName { get; private set; } | |
public string Сrime { get; private set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"Преступник: {FullName} - Преступление ({Сrime})"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment