Question Console.writeline question

J. Scott Elblein

Well-known member
Joined
Dec 14, 2006
Messages
166
Location
Chicago
Programming Experience
10+
When all done coding an app, and ready for public consumption, should all console.writeline's be either deleted or commented out? Or just leave them as is because it doesn't matter?

Also, when debugging, which is the best, most preferred method of viewing info? debug.print or console.writeline?
 
You should replace them with Debug.Write calls. Console.Write calls should only be used if you intend to write to standard output, normally only in Console applications. Calls to Debug class methods is by default not compiled into a release build. Using Debug class also enables you to expand with more advanced debugging tools, for example adding a new TraceListener to Listeners collection, without changing the existing code logic. Debug outputs to Immediate window in IDE (where Console outputs to Output window). If you intend debug/trace information also to be emitted in release build you should use the Trace class, these calls are included by default both in debug/release builds, also here new custom listeners can be added.
Debug Class (System.Diagnostics)
Trace Class (System.Diagnostics)
Console Class (System)
Introduction to Instrumentation and Tracing
help said:
If you use methods in the Debug class to print debugging information and check your logic with assertions, you can make your code more robust without impacting the performance and code size of your shipping product.
I think the reason beginners use Console.writes also in Windows applications to display debug messages is the many code samples where some kind of output/result is displayed with a msgbox/console call. Many code samples also use Console project type implicitly to just "run some code" without the need for a GUI.
 
Back
Top