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 ?
-
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.
Kirk Woll : I am almost certain the OP will be exactly as happy with this solution as the workaround he already mentioned.Kirk Woll : @jsmith, I don't understand why you think ReadKey() provides an advantage over ReadLine() for the purposes of this question. What do you mean, "Which for console you're always waiting for an input."?Kirk Woll : @jsmith, um...so you think the problem the OP had was that he didn't like the word "Line"? (otherwise the "syntax" is identical)jsmith : @Kirk Woll your being awfully opinionated about this one when there is just cause for my answer. From the OP "Isn't there a better looking statement", "something that's more expressive of". Those two quotes make me think he is looking for something that describes the act more. When you are pausing the screen, you are not looking to read a line. But to read a key. Typically the space or enter key.Kirk Woll : @jsmith, you should probably consider calming down. Consider: you just claimed that there was no advantage to your solution -- and now you are saying that it is "better looking" and "more expressive".jsmith : @Kirk Woll you seem to be trolling a bit, saying things like "calm down" based on text is very subjective and argumentative. I am quite calm. I don't quite understand how you know so well what the OP is asking for. I have updated my answer to try and satisfy you.mumtaz : Console.ReadKey() is not a bad suggestion. Its certainly cleaner but its still a statement that does not express the fact that its there just to keep the console from shutting down.From jsmith -
It depends on the context. If you're talking about running a command line, debugging through your code, and then being able to view the results on the console you have two options:
- If you run with the debugger attached (f5), you must use Console.ReadLine
- If you run without the debugger attached (ctrl + f5), it will stay open ... but then you obviously can't debug through.
I'm not sure why that's the default behavior, but there it is :-)
From Joel Martinez -
Hi,
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)
From bahadir arslan
0 comments:
Post a Comment