Update Lesson 2 Task 2

This commit is contained in:
Stanislav Mykhailenko 2023-03-19 13:09:58 +02:00
parent c2a530340c
commit b8010176e1
GPG key ID: 1E95E66A9C9D6A36

View file

@ -13,24 +13,21 @@ List<Person> people = new List<Person>()
new Person("Alex",80) new Person("Alex",80)
}; };
string? userInput;
int minimum; int minimum;
int maximum; int maximum;
do do
{ {
Console.Write("Enter minimum age: "); Console.Write("Enter minimum age: ");
userInput = Console.ReadLine(); } while (!int.TryParse(Console.ReadLine(), out minimum) || minimum < 0 || minimum > 130);
} while (!int.TryParse(userInput, out minimum) || minimum < 0 || minimum > 130);
do do
{ {
Console.Write("Enter maximum age: "); Console.Write("Enter maximum age: ");
userInput = Console.ReadLine(); userInput = Console.ReadLine();
} while (!int.TryParse(userInput, out maximum) || maximum < minimum || maximum > 130); } while (!int.TryParse(Console.ReadLine(), out maximum) || maximum < minimum || maximum > 130);
var selected = from s in people where s.Age >= minimum && s.Age <= maximum select s; var selected = from person in people where person.Age >= minimum && person.Age <= maximum select person;
foreach (Person person in selected) foreach (Person person in selected)
{ {