Untitled

mail@pastecode.io avatar
unknown
csharp
a month ago
2.8 kB
4
Indexable
Never
using System;
using System.Collections.Generic;

namespace ConsoleApp12 {
  internal class Program
  {
      static void Main(string[] args)
      {
          List<Car> cars = new List<Car>();
  
          cars.Add(new Car("11111", "Toyota", "Camry", 2015, "Чёрный"));
          cars.Add(new Car("22222", "Honda", "Civic", 2020, "Серый"));
          cars.Add(new Car("333333", "BMW", "X5", 2018, "Белый"));
          cars.Add(new Car("444444", "Ford", "Mustang", 2014, "Красный"));
          cars.Add(new Car("555555", "Chevrolet", "Cruze", 2019, "Синий"));
  
          Console.Write("VIN-номер двигателя: ");
          string VIN = Console.ReadLine();
          Console.Write("Марка: ");
          string brand = Console.ReadLine();
          Console.Write("Модель: ");
          string model = Console.ReadLine();
          Console.Write("Год выпуска: ");
          int year = int.Parse(Console.ReadLine());
          Console.Write("Цвет: ");
          string color = Console.ReadLine();
  
          cars.Add(new Car(VIN, brand, model, year, color));
  
          cars.Sort((car1, car2) => car1.Year.CompareTo(car2.Year));
  
          Console.WriteLine("\nИнформация о машинах (отсортировано по году выпуска):");
          foreach (Car car in cars)
          {
              Console.WriteLine(car.Info);
          }
  
          Console.Write("\nВведите VIN-номер машины для удаления: ");
          string VINToRemove = Console.ReadLine();
  
          for (int i = 0; i < cars.Count; i++)
          {
              if (cars[i].CompareVIN(VINToRemove))
              {
                  cars.RemoveAt(i);
                  break;
              }
          }
  
          Console.WriteLine("\nИнформация о машинах (удалена машина по VIN номеру):");
          foreach (Car car in cars)
          {
              Console.WriteLine(car.Info);
          }
      }
  }
  
  
  struct Car
  {
      string VIN;
      string brand;
      string model;
      int year;
      string color;
  
      public int Year { 
        get {
          return year;
        } 
      }
  
      public Car(string VIN, string brand, string model, int year, string color)
      {
          this.VIN = VIN;
          this.brand = brand;
          this.model = model;
          this.year = year;
          this.color = color;
      }
  
      public string Info
      {
          get
          {
              return $"VIN: {VIN}, Марка: {brand}, Модель: {model}, Год выпуска: {year}, Цвет: {color}";
          }
      }
  
      public bool CompareVIN(string _VIN)
      {
          return VIN == _VIN;
      }
  }
}