I'm new to C# and I am trying to create a constructor that uses a constructor of the base class. I need to set the values of Engine Class within Constructor of Car class.
Here's what I have now:
public Car (double brand, double model, double engineCap, double fuelCount, double fuelCap )
: base (SetEngine(engineCap, fuelCount, fuelCap))
{
this.brand = brand;
this.model = model;
}
private static Engine SetEngine(double engineCap, double fuelCount, double fuelCap)
{
Engine engine = new Engine(engineCap, fuelCount, fuelCap);
return engine;
}
}
My implementation is probably wrong here. Here's the constructor of the base class:
public Engine(double engineCap, double fuelCount, double fuelCap)
{
this.engineCap = engineCap;
this.fuelCount = fuelCount;
this.fuelCap = fuelCap;
}
The base class of Car is Engine.
Car? Can you post an minimal reproducible example?