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
What is the difference between "Debug.Print" and "Console.WriteLine" in .NET?
提问by Dennis
In .NET when debugging code, is there any difference between using Debug.Print
and Console.WriteLine
?
在 .NET 中调试代码时,使用Debug.Print
和有什么区别Console.WriteLine
吗?
采纳答案by Default
Yes, Console.WriteLine
Writes the specified data, followed by the current line terminator, to the standard output stream.
将指定数据后跟当前行终止符写入标准输出流。
Whereas Debug.Print
Writes a message followed by a line terminator to the trace listeners in the Listeners collection.
将后跟行终止符的消息写入 Listeners 集合中的跟踪侦听器。
Where Listeners
is a List in Debug
.
中Listeners
的列表在哪里Debug
?
A better example might be with a picture. Note that Console.WriteLine
ends up in the Console and the Debug.Print
ends up in the Output window for Visual Studio
一个更好的例子可能是一张图片。请注意,Console.WriteLine
在控制台中Debug.Print
结束,在 Visual Studio 的输出窗口中结束
回答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.
调试类使您能够编写用户看不到的调试输出,此外还提供了通过有意输出检查代码的工具。