From c7cb2e8fd96121de7a843dc6802a24332d6c4236 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 19 Mar 2023 14:23:47 +0200 Subject: [PATCH] Update Lesson 2 Task 4 --- Lesson_2/Task_4/Program.cs | 55 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/Lesson_2/Task_4/Program.cs b/Lesson_2/Task_4/Program.cs index 82a764e..0825052 100644 --- a/Lesson_2/Task_4/Program.cs +++ b/Lesson_2/Task_4/Program.cs @@ -20,11 +20,13 @@ List cars = new List() string? number; -do +while (true) { - Console.Write("Enter number: "); - number = Console.ReadLine(); -} while (number == null); + Console.Write("Enter number: "); + number = Console.ReadLine(); + if (number != null) + break; +} var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id)); @@ -32,36 +34,31 @@ Console.WriteLine(selected); class Owner { - public int Id { get;} - public string Name { get;} - public string Address { get;} + public int Id { get;} + public string Name { get;} + public string Address { get;} - public override string ToString() - { - return "Name: " + Name + ", Address: " + Address; - } + public override string ToString() + { + return "Name: " + Name + ", Address: " + Address; + } - public Owner(int id, string name, string address) - { - Id = id; - Name = name; - Address = address; - } + public Owner(int id, string name, string address) + { + Id = id; + Name = name; + Address = address; + } } class Car { - public string Number { get;} - public int OwnerId { get;} + public string Number { get;} + public int OwnerId { get;} - public override string ToString() - { - return "Number: " + Number + ", Owner ID: " + OwnerId; - } - - public Car(string number, int ownerId) - { - Number = number; - OwnerId = ownerId; - } + public Car(string number, int ownerId) + { + Number = number; + OwnerId = ownerId; + } }