Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace PracticingPolygon
- {
- public abstract class id //sozdaem abstract class
- {
- public abstract int Id { get; set; }
- }
- public class Pc : id
- {
- public override int Id { get; set; }
- public string name { get; private set; }
- public Pc(int Id, string name)
- { this.Id = Id; this.name = name; }
- }
- public class Kabinet : id
- {
- public override int Id { get; set; }
- public string name { get; private set; }
- public List<Pc> Computers = new List<Pc>();
- public Kabinet(int id, string name, List<Pc> computers)
- {
- this.Id = id;
- this.name = name;
- this.Computers = computers;
- }
- public static void GetComputerFromKabinet(List<Kabinet> kabinets, int id)
- {
- for (int i = 0; i < kabinets.Count; i++)
- {
- for (int k = 0; k < kabinets[i].Computers.Count; k++)
- {
- if (kabinets[i].Computers[k].Id == id)
- Console.WriteLine($"Компьютер({kabinets[i].Computers[k].name}) " +
- $"{kabinets[i].Computers[k].Id} " +
- $"был найден в кабинете №{kabinets[i].Id}({kabinets[i].name})");
- }
- }
- }
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- List<Kabinet> kabinets = new List<Kabinet>()
- {
- new Kabinet(1,"Химия",new List<Pc>()
- {
- new Pc(136,"Асус топ 31 вива букк"),
- new Pc(1599, "Марин Турбо 5к"),
- new Pc(33, "UTM super nout 313")
- }),
- new Kabinet(55,"Биология",new List<Pc>()
- {
- new Pc(6343,"31ok"),
- new Pc(159, "tubro33"),
- new Pc(13, "loh1")
- })
- };
- Console.Write("Введите id компьютера который хотите найти: ");
- int id = int.Parse(Console.ReadLine());
- Kabinet.GetComputerFromKabinet(kabinets, id);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment