Debug.Print
和 Debug.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.Print
是 C#
之前的时代。
关于c# - Debug.Print 与 Debug.WriteLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5411999/