Reputation: 190729
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?
}
Upvotes: 16
Views: 30994
Reputation: 1051
You can use;
System.Diagnostics.Debug.WriteLine("hello world");
System.Diagnostics.Debug.Write("hello world");
Debug.WriteLine("hello world");
Debug.Write("hello world");
Don't click "Start without debugging button" if you want to see debug logs.
Upvotes: 0
Reputation: 1452
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.
Upvotes: 2
Reputation: 108975
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.
Upvotes: 28
Reputation: 360
The equivalent to cout/printf in C# is Console.WriteLine(String) or Console.Write(String).
Upvotes: 0
Reputation: 6109
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
Upvotes: 1