Remove overrides

This commit is contained in:
Stanislav Mykhailenko 2023-03-20 17:09:43 +02:00
parent 0914d32a5a
commit a7ada9c683
GPG key ID: 1E95E66A9C9D6A36
8 changed files with 12 additions and 26 deletions

View file

@ -5,11 +5,6 @@ class Product
public string Name { get;}
public float Price { get;}
public override string ToString()
{
return "Name: " + Name + ", Price: " + Price;
}
public Product(string name, float price)
{
Name = name;

View file

@ -45,6 +45,6 @@ for (int i = 0; i < 2; i++)
foreach (Product product in products)
{
Console.WriteLine(product);
Console.WriteLine($"Name: {product.Name}, Price: {product.Price}");
}
}

View file

@ -5,11 +5,6 @@ class Person
public string Name { get;}
public int Age { get;}
public override string ToString()
{
return "Name: " + Name + ", Age: " + Age;
}
public Person(string name, int age)
{
Name = name;

View file

@ -36,5 +36,5 @@ var selected = from person in people where person.Age >= minimum && person.Age <
foreach (Person person in selected)
{
Console.WriteLine(person);
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");
}

View file

@ -6,11 +6,6 @@ class Customer
public int Age { get;}
public string Address { get;}
public override string ToString()
{
return "Name: " + Name + ", Age: " + Age + ", Address: " + Address;
}
public Customer(string name, int age, string address)
{
Name = name;

View file

@ -37,7 +37,7 @@ var selected = from customer in customers where customer.Name == name select cus
foreach (Customer customer in selected)
{
Console.WriteLine(customer);
Console.WriteLine($"Name: {customer.Name}, Age: {customer.Age}, Address: {customer.Address}");
}
var number = selected.Where(customer => customer.Age >= 18).Count();

View file

@ -6,11 +6,6 @@ class Owner
public string Name { get;}
public string Address { get;}
public override string ToString()
{
return "Name: " + Name + ", Address: " + Address;
}
public Owner(int id, string name, string address)
{
Id = id;

View file

@ -34,6 +34,12 @@ while (true)
}
}
var selected = owners.FirstOrDefault(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id));
Console.WriteLine(selected);
try
{
var selected = owners.First(owner => cars.Any(car => car.Number == number && car.OwnerId == owner.Id));
Console.WriteLine($"Name: {selected.Name}, Address: {selected.Address}");
}
catch (InvalidOperationException)
{
Console.WriteLine("Not found.");
}