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_3/Program.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2023-03-15 17:29:32 +00:00
/*
* Lesson 2 Task 3: get a collection of customer, then ask for a name and output the matching users, and also count how many of the selected users are older than 18
* Author: Stanislav Mykhailenko
* License: Unlicense
*/
2023-03-20 00:14:49 +00:00
using CustomerClass;
2023-03-15 17:29:32 +00:00
List<Customer> customers = new List<Customer>()
{
new Customer("Tom", 14, "Street 1"),
new Customer("Bob", 26, "Street 2"),
new Customer("Sam", 10, "Street 3"),
new Customer("Vadim", 57, "Street 4"),
new Customer("Alex", 80, "Street 5"),
new Customer("Alex", 15, "Street 6"),
new Customer("Tom", 65, "Street 7"),
new Customer("Andrew", 33, "Street 8"),
new Customer("Bob", 22, "Street 9"),
new Customer("Alex", 77, "Street 10")
};
string name;
2023-03-15 17:29:32 +00:00
2023-03-19 12:17:57 +00:00
while (true)
2023-03-15 17:29:32 +00:00
{
2023-03-19 12:17:57 +00:00
Console.Write("Enter name: ");
string? input = Console.ReadLine();
if (!string.IsNullOrEmpty(input))
{
name = input;
2023-03-19 12:17:57 +00:00
break;
}
2023-03-19 12:17:57 +00:00
}
2023-03-15 17:29:32 +00:00
2023-03-19 11:12:21 +00:00
var selected = from customer in customers where customer.Name == name select customer;
2023-03-15 17:29:32 +00:00
foreach (Customer customer in selected)
{
2023-03-20 15:09:43 +00:00
Console.WriteLine($"Name: {customer.Name}, Age: {customer.Age}, Address: {customer.Address}");
2023-03-15 17:29:32 +00:00
}
2023-03-19 11:12:21 +00:00
var number = selected.Where(customer => customer.Age >= 18).Count();
2023-03-15 17:29:32 +00:00
Console.WriteLine("Amount of customers older than 18: " + number);