string tastetryk;
ConsoleKeyInfo tast;
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Blue;
Console.Clear();
do
{
Console.WriteLine("Menu");
Console.WriteLine(" ");
Console.WriteLine("Tryk en tast for at vælge funktion");
Console.WriteLine(" ");
Console.WriteLine("I - Beregn strøm");
Console.WriteLine("U - Spænding");
Console.WriteLine("R - Modstand");
Console.WriteLine(" ");
Console.WriteLine("(Esc) for at slutte ");
tast = Console.ReadKey();
tastetryk = tast.Key.ToString();
Console.Clear();
switch(tastetryk)
{
case "I":
Console.WriteLine("du har tastet I");
Console.Write("Tast Q for at komme tilbage");
tast = Console.ReadKey();
break;
case "U":
Console.WriteLine("du har tastet U");
Console.Write("Tast Q for at komme tilbage");
tast = Console.ReadKey();
break;
case "R":
Console.WriteLine("du har tastet R");
Console.Write("Tast Q for at komme tilbage");
tast = Console.ReadKey();
break;
default:
Console.WriteLine("forkert tast");
Thread.Sleep(1000);
Console.Clear();
break;
}
}
while (tast.Key == ConsoleKey.Q);
我为菜单编写了此代码,当我按 I、U 或 R 时,其中一种情况会实现,当您按 Q 时它将返回主菜单。我的问题是当默认为真时,我希望它循环到主菜单而无需按 Q,我尝试使用 tast = Consolekey.Q
对不起我的英语真的很糟糕