Update Lesson 2 Task 4
This commit is contained in:
parent
e6da7ff461
commit
c7cb2e8fd9
1 changed files with 26 additions and 29 deletions
|
@ -20,11 +20,13 @@ List<Car> cars = new List<Car>()
|
||||||
|
|
||||||
string? number;
|
string? number;
|
||||||
|
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("Enter number: ");
|
Console.Write("Enter number: ");
|
||||||
number = Console.ReadLine();
|
number = Console.ReadLine();
|
||||||
} while (number == null);
|
if (number != null)
|
||||||
|
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));
|
||||||
|
|
||||||
|
@ -32,36 +34,31 @@ Console.WriteLine(selected);
|
||||||
|
|
||||||
class Owner
|
class Owner
|
||||||
{
|
{
|
||||||
public int Id { get;}
|
public int Id { get;}
|
||||||
public string Name { get;}
|
public string Name { get;}
|
||||||
public string Address { get;}
|
public string Address { get;}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "Name: " + Name + ", Address: " + Address;
|
return "Name: " + Name + ", Address: " + Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Owner(int id, string name, string address)
|
public Owner(int id, string name, string address)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Address = address;
|
Address = address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Car
|
class Car
|
||||||
{
|
{
|
||||||
public string Number { get;}
|
public string Number { get;}
|
||||||
public int OwnerId { get;}
|
public int OwnerId { get;}
|
||||||
|
|
||||||
public override string ToString()
|
public Car(string number, int ownerId)
|
||||||
{
|
{
|
||||||
return "Number: " + Number + ", Owner ID: " + OwnerId;
|
Number = number;
|
||||||
}
|
OwnerId = ownerId;
|
||||||
|
}
|
||||||
public Car(string number, int ownerId)
|
|
||||||
{
|
|
||||||
Number = number;
|
|
||||||
OwnerId = ownerId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue