Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Console.ReadLine() to keep the Console visible

Tags:

c#

Isn't there a better looking statement (or way) to keep the console from disappearing than the hackish Console.ReadLine() call. Something that's more expressive of the purpose of, more orthogonal to, keeping the Console visible ?

like image 365
explorer Avatar asked Sep 27 '10 18:09

explorer


People also ask

What is the shortcut for console ReadLine?

There is no shortcut(code snippet) for Console. ReadLine() .

What's the difference between console ReadKey (); and console ReadLine ();?

For example, when you use the Console. ReadLine() to input the a string "hello", the program maybe exit and you would not see the output "You input is hello". If you use Console. ReadKey(), the program will wait and would not exit.

What is the difference between console read and console ReadLine?

The only difference between the Read() and ReadLine() is that Console. Read is used to read only single character from the standard output device, while Console. ReadLine is used to read a line or string from the standard output device. Program 1: Example of Console.

What is difference between read ReadKey and ReadLine?

Difference between ReadLine(), Read(), ReadKey() in C# As MSDN is actually pretty clear. Reads the next line of characters from the standard input stream. simply you can say, it read all the characters from user input. (and finish when press enter).


2 Answers

If you are still developing application you can run via Ctrl + F5 (Without debugging) otherwise you can use Console.ReadKey() (same but there is no more option)

like image 99
bahadir arslan Avatar answered Sep 24 '22 20:09

bahadir arslan


You can do:

Console.ReadKey();

Console.ReadLine() is not really hackish, your pausing the screen to wait for input. The input can either be a single key, or a string.

Update

One nice thing about the ReadKey() method is that it "waits, that is, blocks on the thread issuing the ReadKey method, until a character or function key is pressed." MSDN

This is different than ReadLine which takes in a string. Arguably, cleaner.

like image 24
jsmith Avatar answered Sep 26 '22 20:09

jsmith