Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Console window question [modified]

Console window question [modified]

Scheduled Pinned Locked Moved C#
questioncsharpadobecareerlearning
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lurker00
    wrote on last edited by
    #1

    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

    Steve EcholsS 1 Reply Last reply
    0
    • L Lurker00

      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

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      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!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      L 1 Reply Last reply
      0
      • Steve EcholsS Steve Echols

        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!

        L Offline
        L Offline
        Lurker00
        wrote on last edited by
        #3

        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...

        D Steve EcholsS 2 Replies Last reply
        0
        • L Lurker00

          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...

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • L Lurker00

            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...

            Steve EcholsS Offline
            Steve EcholsS Offline
            Steve Echols
            wrote on last edited by
            #5

            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!

            • S
              50 cups of coffee and you know it's on!
              Code, follow, or get out of the way.
            L 1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              L Offline
              L Offline
              Lurker00
              wrote on last edited by
              #6

              So the fault is the books I'm using then? It just seemed strange to me that two books could have missed the apparent need for such a statement. (I used to use Getchar() in C, but it's not in C#.)

              1 Reply Last reply
              0
              • Steve EcholsS Steve Echols

                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!

                L Offline
                L Offline
                Lurker00
                wrote on last edited by
                #7

                "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...

                Steve EcholsS D 2 Replies Last reply
                0
                • L Lurker00

                  "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...

                  Steve EcholsS Offline
                  Steve EcholsS Offline
                  Steve Echols
                  wrote on last edited by
                  #8

                  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!

                  • S
                    50 cups of coffee and you know it's on!
                    Code, follow, or get out of the way.
                  1 Reply Last reply
                  0
                  • L Lurker00

                    "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...

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Or your compiling and running the app in Release, instead of Debug mode.

                    Dave Kreskowiak Microsoft MVP - Visual Basic

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups