gpt4 book ai didi

c# - Debug.Print 与 Debug.WriteLine

转载 作者:IT王子 更新时间:2023-10-29 04:11:17 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com