Unable to run C# in Visual Studio Code

Viewed 104

Whenever I attempt to run C# in VS Code, the program asks for the environment. When I pick ".NET 5+ and .NET core" all that happens is a settings.json file gets opened up as another tab. The second environment option is ".NET Framework 4.x (Windows Only)" all that happens then is that a flash of the code running bar pops up.

Code and environment selector

However it can run Java, but I do not want to do Java. It could be an user error, I wouldn't be surprised if I just couldn't find how to run code.

1 Answers

The problem is that the code runs and exits immediately

You should add Console.ReadKey() at the end of the Main method like this:

using System;


class Program
{
    static void Main(string[] args)
    {
         // Your Code here
         Console.ReadKey(); // At the end of the Main method
    }
}
Related