From a60bfaf1cd6c4b07f37e6a2f2910c3be8f3ad27e Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 19 Mar 2023 14:13:44 +0200 Subject: [PATCH] Update Lesson 2 Task 2 --- Lesson_2/Task_2/Program.cs | 41 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Lesson_2/Task_2/Program.cs b/Lesson_2/Task_2/Program.cs index bb37e70..20ad56c 100644 --- a/Lesson_2/Task_2/Program.cs +++ b/Lesson_2/Task_2/Program.cs @@ -16,37 +16,40 @@ List people = new List() int minimum; int maximum; -do +while (true) { - Console.Write("Enter minimum age: "); -} while (!int.TryParse(Console.ReadLine(), out minimum) || minimum < 0 || minimum > 130); + Console.Write($"Enter minimum age: "); + if (int.TryParse(Console.ReadLine(), out minimum) || minimum >= 0 || minimum <= 130) + break; +} -do +while (true) { - Console.Write("Enter maximum age: "); - userInput = Console.ReadLine(); -} while (!int.TryParse(Console.ReadLine(), out maximum) || maximum < minimum || maximum > 130); + Console.Write($"Enter maximum age: "); + if (int.TryParse(Console.ReadLine(), out maximum) || maximum >= minimum || maximum <= 130) + break; +} var selected = from person in people where person.Age >= minimum && person.Age <= maximum select person; foreach (Person person in selected) { - Console.WriteLine(person); + Console.WriteLine(person); } class Person { - public string Name { get;} - public int Age { get;} + public string Name { get;} + public int Age { get;} - public override string ToString() - { - return "Name: " + Name + ", Age: " + Age; - } + public override string ToString() + { + return "Name: " + Name + ", Age: " + Age; + } - public Person(string name, int age) - { - Name = name; - Age = age; - } + public Person(string name, int age) + { + Name = name; + Age = age; + } }