Search code examples
c#console.readline

Console.ReadLine() accept one char and stop prompt


In a console application,
I use a Console.Readline() to prompt,
It is only use to get an int (1 to 5),
However you can add more char than necessary.

How could I stop the prompt after record one char in my console please ?

You see this underscore _ .
I don't want to see it anymore.

Edit 01/10/15 10pm :

do
{
    string ChoixString = Console.ReadLine();
    Analyseur = int.TryParse(ChoixString, out ChoixInt);
} while (!Analyseur || ChoixInt <= 0 || ChoixInt >= 6);

Final goal : The user can't write more than one char in the prompt.

Solution :

ConsoleKeyInfo ChoixKey = Console.ReadKey();
string ChoixString = ChoixKey.Key.ToString();
Analyseur = int.TryParse(ChoixString, out ChoixInt);    

Thanks for the help.


Solution

  • use this:

    Console.ReadKey();
    

    will read just one character/keypress