This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2023_Stanislav_Mykhailenko/Lesson_2/Task_2/Program.cs

41 lines
913 B
C#
Raw Normal View History

2023-03-15 17:12:01 +00:00
/*
* Lesson 2 Task 2: get a collection of users, then ask minimum and maximum search age and output the matching users
* Author: Stanislav Mykhailenko
* License: Unlicense
*/
2023-03-20 00:14:49 +00:00
using PersonClass;
2023-03-15 17:12:01 +00:00
List<Person> people = new List<Person>()
{
new Person("Tom",18),
new Person("Bob",26),
new Person("Sam",40),
new Person("Vadim",57),
new Person("Alex",80)
};
int minimum;
int maximum;
2023-03-19 12:13:44 +00:00
while (true)
2023-03-15 17:12:01 +00:00
{
2023-03-19 12:20:52 +00:00
Console.Write("Enter minimum age: ");
2023-03-19 12:13:44 +00:00
if (int.TryParse(Console.ReadLine(), out minimum) || minimum >= 0 || minimum <= 130)
break;
}
2023-03-15 17:12:01 +00:00
2023-03-19 12:13:44 +00:00
while (true)
2023-03-15 17:12:01 +00:00
{
2023-03-19 12:20:52 +00:00
Console.Write("Enter maximum age: ");
2023-03-19 12:13:44 +00:00
if (int.TryParse(Console.ReadLine(), out maximum) || maximum >= minimum || maximum <= 130)
break;
}
2023-03-15 17:12:01 +00:00
2023-03-19 11:09:58 +00:00
var selected = from person in people where person.Age >= minimum && person.Age <= maximum select person;
2023-03-15 17:12:01 +00:00
foreach (Person person in selected)
{
2023-03-19 12:13:44 +00:00
Console.WriteLine(person);
2023-03-15 17:12:01 +00:00
}