Console.WriteLine()
和有什么区别和Trace.WriteLine()
?
最佳答案
从“调试”的角度来看这些。
- 我们开始使用
Console.WriteLine()
进行调试 - 后来我们知道总是在控制台上打印调试数据可能并不好。我们甚至可能没有控制台。然后我们开始使用
Debug.WriteLine()
,它在 Visual Studio 输出窗口上打印我的调试信息。 - 然后我们知道我们不应该在 Release模式下打印所有调试信息,因此我们应该在 Release模式下使用
Trace.WriteLine()
。在 Debug模式下,我们可以看到Debug.WriteLine()
和Trace.WriteLine()
的输出。 - 这里有一个非常好的引用:Usage of Trace and Debug
You can use the Trace and the Debug classes separately or together in the same application. In a Debug Solution Configuration project, both Trace and Debug output are active. The project generates output from both of these classes to all Listener objects. However, a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations."
以下是一些您可能会觉得有用的相关项目:
关于console - Console.writeline()/trace.writeline() 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42548412/