Wait for it...
I've been building a couple console applications today and when I run them in the debugger the Command Prompt window they run in closes before I can see what happened. As I'm new to the .NET libraries I didn’t know what command to use to 'pause' program execution. I basically want to put a statement in before the program exits that waits for a keystroke.
Either of these commands will work if the user hits the "Enter" key but any other characters the user types in are displayed (echoed) to the Command Prompt window:
Console.Read ();or
Console.ReadLine();
While this works, I want a solution that would respond to ANY keystroke and not show what the user typed. The following solutions work for .NET 2.0 but not .NET 1.1:
while (Console.KeyAvailable == false);
And my favorite is:
Console.ReadKey(true);
Console.ReadKey(true) does not echo the key the user entered, responds to any key, and doesn't have the iffy forever while loop going on.
1 Comments:
Sound like a good talk. Will you have a transcript/slides available?
Post a Comment
<< Home