Console window question [modified]
-
I'm new to using the Visual C# 2005 Express - is the console window supposed to just flash up and disappear when displaying output from a console program? The book examples I'm using seem to assume so. I've found a code snippet: System.Console.ReadLine(); which does the job, but is it usually necessary to include this line or something similiar to keep the output window from disappearing please? -- modified at 22:31 Saturday 18th November, 2006
-
I'm new to using the Visual C# 2005 Express - is the console window supposed to just flash up and disappear when displaying output from a console program? The book examples I'm using seem to assume so. I've found a code snippet: System.Console.ReadLine(); which does the job, but is it usually necessary to include this line or something similiar to keep the output window from disappearing please? -- modified at 22:31 Saturday 18th November, 2006
Well, usually you'd execute a console app in a command prompt window, so the app would execute and return to the command prompt. If you double click it in explorer, it will open a command prompt window, execute, and when your program is done, it closes the window. ReadLine is waiting for user input, so the app hasn't ended yet, which keeps the window from closing. In other words, it's a hack to keep the window open.
- S 50 cups of coffee and you know it's on!
-
Well, usually you'd execute a console app in a command prompt window, so the app would execute and return to the command prompt. If you double click it in explorer, it will open a command prompt window, execute, and when your program is done, it closes the window. ReadLine is waiting for user input, so the app hasn't ended yet, which keeps the window from closing. In other words, it's a hack to keep the window open.
- S 50 cups of coffee and you know it's on!
-
No this is supposed to run under the MS Visual C# IDE. I have two "step-by-step" type books and both expect the programs to run using the IDE environement; neither seem to consider this problem...
But that's exactly what's happening! You app starts, the console window appears, and when your app is done, the console window closes and you're returned to VIsual Studio. The only way to keep the window open is to put the ReadLine statemnet in there.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
No this is supposed to run under the MS Visual C# IDE. I have two "step-by-step" type books and both expect the programs to run using the IDE environement; neither seem to consider this problem...
Maybe I'm confused or not sure what you're asking. If your console app has no ReadLine at the end, and you run it under the IDE, you'll get "Press any key to continue" prompt. [edit]At least in VS2003[/edit] If you double-click your .exe in windows explorer, it will run it and close the window immediately. Are you saying they need to put Console.ReadLine in there samples, or they shouldn't have it in there?
- S 50 cups of coffee and you know it's on!
-
But that's exactly what's happening! You app starts, the console window appears, and when your app is done, the console window closes and you're returned to VIsual Studio. The only way to keep the window open is to put the ReadLine statemnet in there.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
Maybe I'm confused or not sure what you're asking. If your console app has no ReadLine at the end, and you run it under the IDE, you'll get "Press any key to continue" prompt. [edit]At least in VS2003[/edit] If you double-click your .exe in windows explorer, it will run it and close the window immediately. Are you saying they need to put Console.ReadLine in there samples, or they shouldn't have it in there?
- S 50 cups of coffee and you know it's on!
"If your console app has no ReadLine at the end, and you run it under the IDE, you'll get "Press any key to continue" prompt. [edit]At least in VS2003[/edit]" This must be why my books don't include the readline statement - I'm using the latest version and without the readline the console window behaves the same as in C when you omit the getchar() statement - it briefly flashes and disappears. Presumably they had their reasons for making the change...
-
"If your console app has no ReadLine at the end, and you run it under the IDE, you'll get "Press any key to continue" prompt. [edit]At least in VS2003[/edit]" This must be why my books don't include the readline statement - I'm using the latest version and without the readline the console window behaves the same as in C when you omit the getchar() statement - it briefly flashes and disappears. Presumably they had their reasons for making the change...
Somebody probably complained that they didn't have an "any" key on their keyboard, so they removed it from VS2005 :)
- S 50 cups of coffee and you know it's on!
-
"If your console app has no ReadLine at the end, and you run it under the IDE, you'll get "Press any key to continue" prompt. [edit]At least in VS2003[/edit]" This must be why my books don't include the readline statement - I'm using the latest version and without the readline the console window behaves the same as in C when you omit the getchar() statement - it briefly flashes and disappears. Presumably they had their reasons for making the change...
Or your compiling and running the app in Release, instead of Debug mode.
Dave Kreskowiak Microsoft MVP - Visual Basic