I declare a variable of type Car named ShowOne, create an instance of class Car in the body of the loop, and after the body of the loop I try to assign a reference to the class created in the loop, tell me the correct link passing practice?
static void Main(string[] args)
{
int height = 0;
int peoplePlane = 0;
int peopleShip = 0;
string port = null;
string Plane = "Plane";
string Car = "Avto";
string Ship = "Ship";
Console.WriteLine("Specify vehicle parameters:");
Console.WriteLine(new string('-', 10));
Welcome infoShowWelcome = new Welcome();
Vehicle TransportShow = new Vehicle();
Car ShowOne;
Plane ShowTwo;
Ship ShowThree;
for (int i = 0; i <= 2; i++)
{
string nameTransport;
if (i == 0)
{
nameTransport = Car;
infoShowWelcome.ShowInfo(nameTransport);
Car TransportOne = new Car(infoShowWelcome);
ShowOne = TransportOne;
}
else if (i == 1)
{
nameTransport = Plane;
infoShowWelcome.ShowInfo(nameTransport);
Console.WriteLine("height" + " " + nameTransport + ":");
height = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("people" + " " + nameTransport + ":");
peoplePlane = Convert.ToInt32(Console.ReadLine());
Plane TransportTwo = new Plane(infoShowWelcome, height, peoplePlane);
ShowTwo = TransportTwo;
}
else if (i == 2)
{
nameTransport = Ship;
infoShowWelcome.ShowInfo(nameTransport);
Console.WriteLine("port" + " " + nameTransport + ":");
port = Console.ReadLine();
Console.WriteLine("people" + " " + nameTransport + ":");
peopleShip = Convert.ToInt32(Console.ReadLine());
Ship TransportThree = new Ship(infoShowWelcome, port, peopleShip);
ShowThree = TransportThree;
}
else
{
break;
}
ShowOne.ShowInfo();
ShowTwo.ShowInfo();
ShowThree.ShowInfo();
}
Console.ReadKey();
}
}
VS emphasizes textual ShowOne: the use of a local variable of which is not assigned a value.