What's the difference between Debug.Print
and Debug.WriteLine
? The summary of both in MSDN is the same:
Writes a message followed by a line terminator to the trace listeners in the Listeners collection.
Debug.WriteLine
has more overloads. I can't see a reason why Debug.Print
would be used instead of Debug.WriteLine
?
WriteLine(String) Writes a message followed by a line terminator to the trace listeners in the Listeners collection. WriteLine(Object) Writes the value of the object's ToString() method to the trace listeners in the Listeners collection.
Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug.
Debug. WriteLine writes to the debug output. You can see it in your debugger and save it from there.
They both do the same thing, but its interesting that Debug.Print
will only take a string, while Debug.WriteLine
will accept an object which ends up calling the object's ToString
method.
With Reflector:
[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); }
I'd be willing to bet that Debug.Print
was a hold over from Visual Basic.
Edit: From a tutorial on 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.
Sure sounds like Debug.Print
was a hold over from pre-C#
days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With