Function in Class

This commit is contained in:
Frozd
2025-09-18 08:34:06 +02:00
parent 1654c4d722
commit 7d71783102
11 changed files with 1154 additions and 24 deletions

View File

@@ -29,9 +29,9 @@ namespace CarManagerV2
public static void removeCar(Car car)
{
cars = SafeManager.readCars("cars.csv");
Console.WriteLine(cars);
cars.Remove(car);
Console.WriteLine(cars);
Car existingCar = getCarById(car.Id);
if (existingCar == null) return;
cars.Remove(existingCar);
SafeManager.saveCars("cars.csv", cars);
}
@@ -47,12 +47,13 @@ namespace CarManagerV2
}
}
public static void createCar(string make, string model, int year, string color, int mileage, decimal price)
public static Car createCar(string make, string model, int year, string color, int mileage, decimal price)
{
cars = SafeManager.readCars("cars.csv");
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
Car newCar = new Car(newId, make, model, year, color, mileage, price);
cars.Add(newCar);
addCar(newCar);
return newCar;
}
}
}