简体   繁体   English

无法在 Visual Studio Code 中运行 C#

[英]Unable to run C# in Visual Studio Code

Whenever I attempt to run C# in VS Code, the program asks for the environment.每当我尝试在 VS Code 中运行 C# 时,程序都会询问环境。 When I pick ".NET 5+ and .NET core" all that happens is a settings.json file gets opened up as another tab.当我选择“.NET 5+ 和 .NET 核心”时,所有发生的事情都是设置。json 文件作为另一个选项卡打开。 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.第二个环境选项是“.NET Framework 4.x (Windows Only)”,然后弹出代码运行栏的 flash。

代码和环境选择器

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.但是它可以运行 Java,但我不想运行 Java。这可能是一个用户错误,如果我只是找不到如何运行代码,我不会感到惊讶。

The problem is that the code runs and exits immediately问题是代码运行并立即退出

You should add Console.ReadKey() at the end of the Main method like this:您应该在 Main 方法的末尾添加Console.ReadKey() ,如下所示:

using System;


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM