C# .NET 中的“Debug.Print”和“Console.WriteLine”有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18871505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:28:21  来源:igfitidea点击:

What is the difference between "Debug.Print" and "Console.WriteLine" in .NET?

c#.netvb.net

提问by Dennis

In .NET when debugging code, is there any difference between using Debug.Printand Console.WriteLine?

在 .NET 中调试代码时,使用Debug.Print和有什么区别Console.WriteLine吗?

采纳答案by Default

Yes, Console.WriteLine

是的,Console.WriteLine

Writes the specified data, followed by the current line terminator, to the standard output stream.

将指定数据后跟当前行终止符写入标准输出流。

Whereas Debug.Print

Debug.Print

Writes a message followed by a line terminator to the trace listeners in the Listeners collection.

将后跟行终止符的消息写入 Listeners 集合中的跟踪侦听器。

Where Listenersis a List in Debug.

Listeners的列表在哪里Debug

A better example might be with a picture. Note that Console.WriteLineends up in the Console and the Debug.Printends up in the Output window for Visual Studio

一个更好的例子可能是一张图片。请注意,Console.WriteLine在控制台中Debug.Print结束,在 Visual Studio 的输出窗口中结束

Console.WriteLine vs Debug.Print

Console.WriteLine 与 Debug.Print

回答by pt12lol

Debug writes the message to the Output > Debug. Console.WriteLine writes a message to standard output (console).

调试将消息写入输出 > 调试。Console.WriteLine 将消息写入标准输出(控制台)。

回答by Thilina H

However, the big difference is in concept rather than functionality. The Console.WriteLine is, as I mentioned, meant to be the output channel in console applications. Debug.Print is there to an aid to you, the programmer.

然而,最大的区别在于概念而不是功能。正如我提到的,Console.WriteLine 是控制台应用程序中的输出通道。Debug.Print 可以帮助您,程序员。

The debug class enables you to write debug outputs that the users can't see, and in addition provides tools to check your code through deliberate output.

调试类使您能够编写用户看不到的调试输出,此外还提供了通过有意输出检查代码的工具。