Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug.Print vs. Debug.WriteLine

Tags:

c#

debugging

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?

like image 682
Craig T Avatar asked Mar 23 '11 21:03

Craig T


People also ask

What is 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.

Where does debug WriteLine go in Visual Studio?

Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug.

Where does debug WriteLine write to?

Debug. WriteLine writes to the debug output. You can see it in your debugger and save it from there.


1 Answers

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.

like image 115
Metro Smurf Avatar answered Sep 29 '22 19:09

Metro Smurf