c# - Debug.Print 与 Debug.WriteLine

标签 c# debugging

Debug.PrintDebug.WriteLine 有什么区别?两者在MSDN中的总结是一样的:

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

Debug.WriteLine 有更多重载。我看不出为什么要使用 Debug.Print 而不是 Debug.WriteLine 的原因?

最佳答案

它们都做同样的事情,但有趣的是 Debug.Print 只会接受一个字符串,而 Debug.WriteLine 会接受一个最终调用对象的 ToString 方法。

带反射器:

[Conditional("DEBUG")]
public static void Print(string message){
    TraceInternal.WriteLine(message);
}

[Conditional("DEBUG")]
public static void WriteLine(string message){
    TraceInternal.WriteLine(message);
}

[Conditional("DEBUG")]
public static void WriteLine(object value)
{
    TraceInternal.WriteLine(value);
}

我敢打赌,Debug.Print 是 Visual Basic 的延续。

编辑:来自 Tracing VB.NET Windows Application 上的教程:

In Visual Basic.NET 2005, the Debug.Write, Debug.WriteIf, Debug.WriteLine, and Debug.WriteLineIf methods have been replaced with the Debug.Print method that was available in earlier versions of Visual Basic.

听起来确实像 Debug.PrintC# 之前的时代。

关于c# - Debug.Print 与 Debug.WriteLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5411999/

相关文章:

c# - 如何以编程方式向 log4net 添加过滤器?

javascript - 浏览器加载 html 页面时出现脚本错误

arrays - 用数组存储数组 - Swift

debugging - gdb中调试的应用程序输出问题

c# - ASP.NET MVC 2 中的 httppost、httpput 等属性如何工作?

c# - 从继承具体类对抽象类的类型推断

c# - 我要开发网络 session 软件

debugging - vscode调试器配置: cwd

c++ - 如何使用 CMake 在 KDevelop 中定义多配置?

在 Linux 和 Windows 中用 C 语言编码。任何适当的面向调试的以 C 为中心的 IDE?