With C++/C, the easiest way of debugging is to use cout/printf to print out what is going on to the console.
What would be the equivalent method in WPF/C#?
I thought about using MessageBox(), but WPF doesn't seem to support this function. I also thought about using logging function, but I wonder it's too complicated than printf/cout.
I can use break points in Visual Studio, even so, I need some command to set a break point.
if (ABC())
{
// What command should be here to set a break point?
}
Debug.Write
and Debug.WriteLine
are the methods to use, in a release build (or, more correctly, one where DEBUG
is not defined) they will be compiled out. To include in builds with TRACE
defined (eg. debug configuration for both debug and release) then use Trace.Write
and Trace.WriteLine
.
If you have a debugger attached (eg. Visual Studio) then it should show these (in VS its the Output tool window).
When not running in a debugger a tool like Sysinternal's Debug View will show this output.
You could use System.Diagnostics.Debug.WriteLine.
For breaking into debugger, use System.Diagnostics.Debugger.Break. Instead of if() { Break; } construct, please consider Debug.Assert related routines.
You can use MessageBox.Show()
Or Debug.Trace
Or make the application type a console app (in project settings) and use Console.WriteLine()
Or use System.Diagnostics tracing
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