Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTask2FreeCriminals
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Prison prison = new Prison();
- prison.FreeCriminals("Антиправительственное");
- }
- }
- public class Prison
- {
- private List<Criminal> _criminals;
- public Prison()
- {
- FillCriminals();
- }
- public void FreeCriminals(string crime)
- {
- Console.WriteLine("Список заключенных до амнистии:");
- ShowCriminals();
- List<Criminal> filteredCriminals = _criminals.Where(criminal => criminal.Crime != crime).ToList();
- _criminals = filteredCriminals;
- Console.WriteLine("Список заключенных после амнистии:");
- ShowCriminals();
- }
- private void ShowCriminals()
- {
- Console.WriteLine("Преступники:");
- foreach (var criminal in _criminals)
- {
- criminal.ShowInfo();
- }
- }
- private void FillCriminals()
- {
- _criminals = new List<Criminal>
- {
- new Criminal("gdfsgdfg", "Антиправительственное"),
- new Criminal("dfsdfsd", "грабеж"),
- new Criminal("bfgnbfn", "убийство"),
- new Criminal("bnvncvbn", "Антиправительственное"),
- new Criminal("gdfxvxcvxcsgdfg", "грабеж"),
- new Criminal("xcvzxcc", "Антиправительственное"),
- new Criminal("xvvxv", "грабеж"),
- new Criminal("nfhnn", "Антиправительственное"),
- new Criminal("dgdfgdg", "убийство")
- };
- }
- }
- public class Criminal
- {
- public Criminal(string name, string crime)
- {
- Name = name;
- Crime = crime;
- }
- public string Name { get; private set; }
- public string Crime { get; private set; }
- public void ShowInfo()
- {
- Console.WriteLine($"{Name} ({Crime})");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement