Update Lesson 2 Task 2
This commit is contained in:
parent
722437f3f7
commit
a60bfaf1cd
1 changed files with 22 additions and 19 deletions
|
@ -16,37 +16,40 @@ List<Person> people = new List<Person>()
|
||||||
int minimum;
|
int minimum;
|
||||||
int maximum;
|
int maximum;
|
||||||
|
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter minimum age: ");
|
Console.Write($"Enter minimum age: ");
|
||||||
} while (!int.TryParse(Console.ReadLine(), out minimum) || minimum < 0 || minimum > 130);
|
if (int.TryParse(Console.ReadLine(), out minimum) || minimum >= 0 || minimum <= 130)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter maximum age: ");
|
Console.Write($"Enter maximum age: ");
|
||||||
userInput = Console.ReadLine();
|
if (int.TryParse(Console.ReadLine(), out maximum) || maximum >= minimum || maximum <= 130)
|
||||||
} while (!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;
|
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)
|
||||||
{
|
{
|
||||||
Console.WriteLine(person);
|
Console.WriteLine(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person
|
class Person
|
||||||
{
|
{
|
||||||
public string Name { get;}
|
public string Name { get;}
|
||||||
public int Age { get;}
|
public int Age { get;}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "Name: " + Name + ", Age: " + Age;
|
return "Name: " + Name + ", Age: " + Age;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Person(string name, int age)
|
public Person(string name, int age)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Age = age;
|
Age = age;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue