'Unable to run C# in Visual Studio Code

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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve