5

The C# Console.ReadLine() command is simply ignored when I run my code using mono filename.exe after having compiled it using gmcs filename.cs. What could be happening? Even when I try running the simple code bellow it skips right to the end as if it ran nothing..

static void Main(string[] args) {
    string value = Console.ReadLine();
    Console.WriteLine("You entered: {0}", value);
    Console.WriteLine("Press ENTER to continue...");
    Console.ReadLine();   // Returns immediately.
    Console.WriteLine("Continuing....");
}
Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
user2142733
  • 71
  • 1
  • 6
  • Are you running this from mono develop? – JaredPar Mar 16 '13 at 03:22
  • You created this as a console app, right? Not as a windows forms or WPF app? – Jim Mischel Mar 16 '13 at 03:50
  • I created it using textWrangler and compiled it using the console on a mac. – user2142733 Mar 16 '13 at 04:21
  • 1
    It's a stab in the dark, but could it be a problem with Windows and OS X having different new-line characters? Windows uses `CR+LF`, and OS X uses `LF`. Could the keyboard be sending `CR+LF` and each `ReadLine` command is reading both the `CR` and the `LF` as individual new lines? What happens if you add a third `Console.ReadLine()`, or better yet what happens if you write the results of a looped `Console.ReadKey()`? – Hand-E-Food Mar 17 '13 at 22:28

2 Answers2

0

I'm guessing this is your problem.

C# why is it skipping my console.readline()?

I had seen this before in my own stuff and couldn't remember the solution. Basically, you are having the user press the carriage return which sends carriage return and line feed, causing the readline to get triggered. Would you be able to use a Read..Key(someCharacter);

Community
  • 1
  • 1
gcoleman0828
  • 1,541
  • 3
  • 30
  • 49
0

This is unlikely but a sticky return key can cause this issue. By the way you describe, the runtime respects your first Console.ReadLine();, but ignores the second? If so, and you were using an older keyboard, maybe the return key doesn't return to the 'unpressed' condition as quickly as you would like. This would cause the issue you are seeing.

JMK
  • 27,273
  • 52
  • 163
  • 280