24

In .NET when debugging code, is there any difference between using Debug.Print and Console.WriteLine?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dennis
  • 3,528
  • 4
  • 28
  • 40
  • 1
    Debug.Print prints to the output and used for tracing! Console.Writeline actually writes the output to the console. – Nilesh Sep 18 '13 at 11:59

3 Answers3

41

Yes, Console.WriteLine

Writes the specified data, followed by the current line terminator, to the standard output stream.

Whereas Debug.Print

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

Where Listeners is a List in Debug.

A better example might be with a picture. Note that Console.WriteLine ends up in the Console and the Debug.Print ends up in the Output window for Visual Studio

Console.WriteLine vs Debug.Print

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
default
  • 11,485
  • 9
  • 66
  • 102
2

However, the big difference is in concept rather than functionality. The Console.WriteLine is, as I mentioned, meant to be the output channel in console applications. Debug.Print is there to an aid to you, the programmer.

The debug class enables you to write debug outputs that the users can't see, and in addition provides tools to check your code through deliberate output.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thilina H
  • 5,754
  • 6
  • 26
  • 56
0

Debug writes the message to the Output > Debug. Console.WriteLine writes a message to standard output (console).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pt12lol
  • 2,332
  • 1
  • 22
  • 48