PSSGCSim
PSSGCSim

Reputation: 1287

Reading line from console

I'm experiencing problem with reading input from user. Every time it shrinks your input by first character. Like:

input

test

what program reads

est

I'm using this simple code:

string input = Console.ReadLine();
Console.WriteLine(input + " >> " + psbhc_service.Encrypt(input));

Upvotes: 1

Views: 56

Answers (1)

Matthew Watson
Matthew Watson

Reputation: 109537

Make sure you haven't got a Console.ReadKey() before the ReadLine().

For example, this will exhibit the behaviour you described:

while (true)
{
    Console.ReadKey();
    Console.WriteLine(Console.ReadLine());
}

If you want to check whether a key is available, use Console.KeyAvailable, which doesn't consume the keystroke.

Upvotes: 3

Related Questions