Why doesn't Console.WriteLine work in Visual Studio Code?

I have scripts and coderunner installed in Visual Studio Code. When I run a simple program that includes Console.WriteLine("Test"), I do not see any output. The program runs successfully and exits with code 0.

Any suggestions?

Here is the whole code in case anyone is interested:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Test");
    }
}
+7
source share
6 answers

If you are just trying to run the cs file without a project, etc., then the problem is that the code runner treats the file as a script. Thus, the main method is not actually called, as it would be when starting a console application.

, Program.Main(null); . - launch.json config. Program.Main , VS-, . . .

using System;
class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Test");
    }
}

Program.Main(null);

: fooobar.com/questions/14007790/...

+3

launch.json "console":

:

  "console": "internalConsole",

To:

  "console": "externalTerminal",

.

+4

, ctrl + F5. . , Console.ReadLine(); console.writeline, , .

0

Console.Readline()
Console.Read()
Console.ReadKey()

:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Test");
        Console.ReadLine();
    }
}
-1

, , , . , , :

  • Console.Read();

  • Console.ReadLine();

( , , ).

, , 'enter' .

-2

Console.WriteLine("Hello");
string name = Console.ReadLine();
-3

Source: https://habr.com/ru/post/1674121/


All Articles