1

Hey y'all I'm writing my first program and I've chosen C#. I'm trying to write a little dialogue at the beginning of what will be a multiple choice quiz. According to youtube videos and forums I should be able to do a WriteLine followed by a blank ReadLine and the program should continue after anything is entered. But when I provide it with input it just drops down a line and continues to wait for a prompt. Is this an issue caused by vscode? Also I am just modifying the basic hello world script. Here is some code. thanks.

using System;

namespace C_
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("In 5 seconds the teacher will begin to speak...");
            Console.ReadLine();
            Console.WriteLine("You will be tested for aptitude in the realm of being a worthy human.");
            Console.ReadLine();
        }
    }
}
ghstdg
  • 21
  • 2
  • *But when I provide it with input it just drops down a line and continues to wait for a prompt.* By "drops down a line" do you mean the second line of text is shown? You're calling `ReadLine` twice, so after you enter a line it will continue to the next `ReadLine` and wait for you to enter a line again. – Joe Sewell Mar 20 '20 at 19:06
  • When it comes to properly using and understanding an API, I would suggest relying on [documentation](https://learn.microsoft.com/dotnet/api/system.console.readline) and books, not YouTube videos or forums or even a Q&A site like this. – Lance U. Matthews Mar 20 '20 at 19:20
  • "do you mean the second line of text is shown?" No. There is an arrow to the left and a prompt if I hit enter or anything else then enter it adds another arrow on the next line below and continues to prompt me. Same happens 4,5,and 6 strokes of the enter button – ghstdg Mar 20 '20 at 19:40
  • @BACON: "When it comes to properly using and understanding an API, I would suggest relying on documentation and books, not YouTube videos or forums or even a Q&A site like this." TBH This is clearly solid advice. However, I'm having trouble understanding the language on microsofts website and other technical documents. Until I'm in a little deeper I think youtube, forums, this site, etc are more accessible to me as a layman. – ghstdg Mar 20 '20 at 19:44
  • Perhaps I should have included "quality instruction" (courses, blogs, etc. from subject matter experts) as a third suggestion. That might overcome the obstacle of accessibility without relying on, well, yahoos on the internet. Also, I tried your code and see what the problem is: it's stuck in the `Debug Console`. See [https://stackoverflow.com/q/41195432/150605](https://stackoverflow.com/questions/41195432/debug-console-window-cannot-accept-console-readline-input-during-debugging/45479761). (It wasn't an API usage issue after all, so I suppose that might make me one of those same yahoos.) – Lance U. Matthews Mar 20 '20 at 20:15
  • Does this answer your question? [Debug Console window cannot accept Console.ReadLine() input during debugging](https://stackoverflow.com/questions/41195432/debug-console-window-cannot-accept-console-readline-input-during-debugging) – Lance U. Matthews Mar 20 '20 at 20:16
  • Yes, in fact, it does. @Barns got to me first though. – ghstdg Mar 20 '20 at 21:52

1 Answers1

10

This is an issue with the Visual Studio Code environment. The launch.json contains setting that will control the way your app executes.

By default the attribute: "console" is set to the value "internalConsole". So it looks like this:
"console": "internalConsole"

In order to use Console.ReadLine(); or Console.ReadKey(); change to:
"console": "integratedTerminal"

And then switch to "Terminal" in the lower panel while debugging.

In order to 'automatically' switch to the "Terminal" panel add:
"internalConsoleOptions": "neverOpen"

Barns
  • 4,850
  • 3
  • 17
  • 31