Ich könnte die switch-Anweisung nur zweimal durchlaufen. Nach dem zweiten Mal schließt sich die Konsole, egal welche Option ich aus dem Schalterfall gewählt habe. Wie sollte ich meinen Code ändern, damit der Benutzer den Switch-Fall so lange wiederholen kann, bis er sich entscheidet aufzuhören?Wie wird die while-Schleife nach zweimaliger Ausgabe der Anweisung fortgesetzt?
Vielen Dank für Ihre Vorschläge.
int userChoice = 0;
Console.WriteLine("This is an application. It has many different modes.");
Console.WriteLine("You can activate the mode of the application, which can be inserting, retrieving, printing, saving or uploading.");
Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");
string mode = Console.ReadLine();
switch (mode)
{
case "I":
Console.WriteLine("You have chosen to insert the data.");
break;
case "R":
Console.WriteLine("You have chosen to retrieve the data.");
break;
case "P":
Console.WriteLine("You have chosen to print the data.");
break;
case "S":
Console.WriteLine("You have chosen to save the data.");
break;
case "U":
Console.WriteLine("You have chosen to upload the data.");
break;
case "T":
Console.WriteLine("You have chosen to terminate the application.");
return;
}
// Two modes, quit option
if (mode == "I" || mode == "R")
{
Console.WriteLine("The application will stay in the insert or retrieve modes. Press 'Q' to exit to the modes to return to the main menu.");
}
while (userChoice != 0)
{
Console.WriteLine("Please choose one of the modes {0}.", userChoice);
userChoice++;
}
Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");
Console.ReadLine();
benötigen Sie den Code ausgeführt werden soll, setzen * innen * die Schleife –
Ihre switch-Anweisung in einer Schleife ist nicht –