I have this code in which I take in data from the user to create a vehicle object. The only problem is, since they are different data types I am asking for I have to switch between Read
and ReadLine
. When the code gets down to the ReadLine
part, it prints out all of my WriteLine
statements instead of just waiting for input from the first.
Code:
Console.Write("What would you like to do? ");
s = Console.ReadLine();
if (s == "1")
{
Console.Write("Please Enter the vehicle ID: \n");
ID = Console.Read();
Console.Write("Please enter the vehicle make: \n");
make = Console.ReadLine();
Console.Write("Please enter the vehicle model: \n");
model = Console.ReadLine();
Console.Write("Please enter the vehicle year: \n");
year = Console.Read();
Vehicle v;
v = new Vehicle
{
Id = ID,
Make = make,
Model = model,
Year = year
};
Create(v);
}
Output:
Please enter the vehicle ID:
Input: 123
Please enter the Vehicle make:
Please enter the Vehicle model:
Here is my class definition, as requested in the comments:
public class Vehicle
{
public int Id { get; set; }
public int Year { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public static string Class { get; set; }
public interface VehicleService
{
List<Vehicle> Get();
Vehicle Get(int id);
void Create(Vehicle vehicle);
void Update(Vehicle vehicle);
void Delete(Vehicle vehicle);
}
}
Any help would be greatly appreciated.