简体   繁体   English

在 Visual Studio 中执行 C# 代码时出现控制台问题

[英]Issue with console when executing C# code in Visual Studio

When executing any code in the Visual Studio console, if there is an error in my code instead of displaying an error message it simply displays the most recent correct output, even if the code for it has been deleted, is there a setting that I accidentally turned on that is doing this?在 Visual Studio 控制台中执行任何代码时,如果我的代码中出现错误而不是显示错误消息,它只会显示最近正确的 output,即使它的代码已被删除,是否存在我不小心的设置开机就是这样做的? If so, how can I disable it?如果是这样,我该如何禁用它?

I am using Visual Studio 2019, C#, console app.我正在使用 Visual Studio 2019、C#、控制台应用程序。 I have tried saving the new code then running it but that doesn't make a difference, I've tried quiting out of the app and reopening it or switching to a new project and that doesn't work either.我尝试保存新代码然后运行它,但这并没有什么不同,我尝试退出应用程序并重新打开它或切换到一个新项目,但这也不起作用。

If I were to type:如果我要输入:

Console.WriteLine("Hello world!");

Console.ReadLine();

which is correct code, it will display: Hello world!这是正确的代码,它将显示: Hello world!

If I then were to change it to:如果我当时将其更改为:

Console.WriteLine("Goodbye world")

Console.ReadLine()

Instead of giving me an error message, since I forgot the semicolons, it would just print: Hello world.由于我忘记了分号,它不会给我一条错误消息,它只会打印:Hello world。 again.再次。

I would expect there to be an error message instead of what happens since the previous program I used did that.我希望会有一条错误消息,而不是自从我使用的上一个程序这样做以来发生的情况。

Ps: Sorry if this question is obvious or self explanatory or if it's just me who is wrong but it's really stressing me out seeing correct output from the wrong code. Ps:对不起,如果这个问题很明显或不言自明,或者只是我错了,但这真的让我从错误的代码中看到正确的 output 感到压力。

I believe you're looking for Tools->Options->Projects and Solutions->Build And Run .我相信您正在寻找Tools->Options->Projects and Solutions->Build And Run

The default (which fails build on error) is what you see on screen ( On Run, when build or deployment errors occur part):默认值(构建错误时失败)是您在屏幕上看到的内容(运行时,发生构建或部署错误部分):

在此处输入图像描述

The one that you're using now and trying to get rid of, most likely, is "Launch old version".您现在正在使用并试图摆脱的最有可能是“启动旧版本”。

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

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