I have a problem with my code. Mostly I have no problems with the switch statement combined with the do-while loop. I think the problem lies in the ConsoleKey function, but since I start my adventure with programming, I can't solve the problem. So I hope someone from this great community will help me. If it's possible I want to use press key to choose an option in switch statement. Thanks for help. P.S. English is not my first language, so if I misspelled anything, sorry.
static void Main(string[] args)
{
Console.WriteLine("Attention");
Console.WriteLine("Choose 1-2");
var inputData = Console.ReadKey();
do
{
switch (inputData.Key)
{
case ConsoleKey.X:
Console.WriteLine("action 1");
break;
case ConsoleKey.Y:
Console.WriteLine("action 2");
break;
default:
Console.WriteLine("Default");
break;
}
} while (inputData.Key != ConsoleKey.Escape);
Console.ReadKey();
}
Console.WriteLine("Attention");
Console.WriteLine("Choose 1-2");
ConsoleKeyInfo inputData = Console.ReadKey();
do
{
switch (inputData.Key)
{
case ConsoleKey.X:
Console.WriteLine("action 1");
break;
case ConsoleKey.Y:
Console.WriteLine("action 2");
break;
default:
Console.WriteLine("Default");
break;
}
Console.WriteLine("Choose 1-2");
inputData = Console.ReadKey();
} while (inputData.Key != ConsoleKey.Escape);
Console.ReadKey();