Advertisement
nikitaTheSlayer

LINQ

May 27th, 2022
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace LINQ
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int growth;
  12.             double weight;
  13.             string nationality;
  14.  
  15.             List<Criminal> criminals = new List<Criminal> { new Criminal("Иванов Иван Иванович", "Русский", 180, 55.5, true),
  16.                                                             new Criminal("Сидоров Сидор Сидорович", "Русский", 170, 60.5, false),
  17.                                                             new Criminal("Джонсов Джон", "Пендос", 175, 90.5, false),
  18.                                                             new Criminal("Ибрагимов Ибрагим Ибрагимович", "Азербайджанец", 180, 55.5, false),
  19.                                                             new Criminal("Подпивасов Подпивас Подпивасович", "Украинец", 180, 55.5, false),
  20.                                                             new Criminal("Чукчеев Чукча Чукчевич", "Чекчеец", 180, 55.5, true),
  21.                                                             new Criminal("Петров Петро Петров", "Фин", 180, 55.5, false),
  22.             };
  23.             Console.WriteLine("Введите рост преступника: ");
  24.             growth = Convert.ToInt32(Console.ReadLine());
  25.             Console.WriteLine("Введите вес преступника");
  26.             weight = Convert.ToDouble(Console.ReadLine());
  27.             Console.WriteLine("Введите национальность преступника");
  28.             nationality = Console.ReadLine();
  29.  
  30.             Console.Clear();
  31.  
  32.             var result = from Criminal criminal in criminals
  33.                          where criminal.Growth == growth
  34.                          where criminal.Weight == weight
  35.                          where criminal.Nationality.ToUpper() == nationality.ToUpper()
  36.                          where criminal.InPrison == false
  37.                          select criminal;
  38.  
  39.             Console.WriteLine("По заданными вами параметрами найдены следующие преступники: ");
  40.  
  41.             foreach (var criminal in result)
  42.             {
  43.                 Console.WriteLine(criminal.FullName);
  44.             }
  45.         }
  46.     }
  47.  
  48.     class Criminal
  49.     {
  50.         public string FullName { get; private set; }
  51.         public string Nationality { get; private set; }
  52.         public int Growth { get; private set; }
  53.         public double Weight { get; private set; }
  54.         public bool InPrison { get; private set; }
  55.  
  56.         public Criminal(string fullName, string nationality, int growth, double weight, bool inPrison)
  57.         {
  58.             FullName = fullName;
  59.             Nationality = nationality;
  60.             Growth = growth;
  61.             Weight = weight;
  62.             InPrison = inPrison;
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement