WHY WONT THIS WORK? How does array initializing even work?
Posts 1–2 of 2 · Page 1 of 1
WHY WONT THIS WORK? How does array initializing even work?
I got this:
class Turbo
{
private Car[] car;
public Turbo(Car[] car)
{
this.car = car;
}
AND THIS
public string raisecarspeed(int speed)
{
for (int i = 0; i < car.Length; i++)
{
carnumber++;
if (car[i].CarSpeed + speed <= car[i].MaxSpeed)
{
car[i].CarSpeed += speed;
message += "Car number #" + carnumber + " has increased his speed by " + speed + ", his speed is now " + car[i].CarSpeed + "\r\n";
}
else
{
message += "Car number #" + carnumber + " can not increase his speed by " + speed + " because his max speed is " + car[i].MaxSpeed + "\r\n";
}
}
return message;
}
It's just suppost to go through all the car arrays that I initialized and his shit. But when I insert a breakpoint, it shows that the "car" variable is empty even after initialization. This is what my initialization looks like:
Car[] car = new Car[4];
car[0] = new Car(100, 200);
car[1] = new Car(50, 200);
car[2] = new Car(150, 400);
car[3] = new Car(75, 250);
turbo = new Turbo(car);
The constructor of car just adjusts the carspeed (first number) and the maxspeed ( second number). Am I using the array object thing wrong?
NVM AFTER ALOT OF FRUSTRATION THE STUDIO JUST MAGICALLY DECIDED THAT , THAT WAS THE TIME THEY WERE GOING TO TELL ME THAT I FORGOT A CAPITAL S