Make strings non-nullable by using different variables to just check input
This commit is contained in:
parent
6548c0b5f0
commit
0914d32a5a
3 changed files with 19 additions and 9 deletions
|
@ -10,16 +10,20 @@ List<Product> products = new List<Product>();
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
string? name;
|
string name;
|
||||||
float price;
|
float price;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write($"Enter product {i + 1} name: ");
|
Console.Write($"Enter product {i + 1} name: ");
|
||||||
name = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
if (name != null)
|
if (!string.IsNullOrEmpty(input))
|
||||||
|
{
|
||||||
|
name = input;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,14 +20,17 @@ List<Customer> customers = new List<Customer>()
|
||||||
new Customer("Alex", 77, "Street 10")
|
new Customer("Alex", 77, "Street 10")
|
||||||
};
|
};
|
||||||
|
|
||||||
string? name;
|
string name;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter name: ");
|
Console.Write("Enter name: ");
|
||||||
name = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
if (name != null)
|
if (!string.IsNullOrEmpty(input))
|
||||||
|
{
|
||||||
|
name = input;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var selected = from customer in customers where customer.Name == name select customer;
|
var selected = from customer in customers where customer.Name == name select customer;
|
||||||
|
|
|
@ -21,14 +21,17 @@ List<Car> cars = new List<Car>()
|
||||||
new Car("789GHI", 3),
|
new Car("789GHI", 3),
|
||||||
};
|
};
|
||||||
|
|
||||||
string? number;
|
string number;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter number: ");
|
Console.Write("Enter number: ");
|
||||||
number = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
if (number != null)
|
if (!string.IsNullOrEmpty(input))
|
||||||
|
{
|
||||||
|
number = input;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id));
|
var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id));
|
||||||
|
|
Reference in a new issue