+ 1
So... I need to get an input from the user, just one char,
without him having to click enter, so readLine not good. I guess i need the ReadKey() method but don't know how to get the pressed key into a variable. string pressedButon = Console.ReadKey(); ----> give me an error can you help me please?
5 Answers
+ 2
In the playground my vode does not work because it is a remote server.
ReadKey
Is just like
Readline
ReadLine causes the playground to ask for input.
ReadKey does not work in the playground so it also does not ask for input.
Please copy the code to your liocal IDE.
+ 1
Console.ReadKey does not return a string but a ConsoleKeyInfo
https://code.sololearn.com/cR5Y86SPCE4Q
https://docs.microsoft.com/en-us/dotnet/api/system.console.readkey?view=netframework-4.8
0
sneeze,your code says i pressed 0 but nothing is pressed..?
0
use ConsoleKeyInfo key = Console.ReadKey();
Then you can convert it to Char: Char keyChar = Convert.ToChar(key);
0
Ok, thanks