Chapter 10. Basic Debugging
The debugger is your friend. There is simply no more powerful tool than a debugger for learning C# and for writing quality C# programs. The debugger helps you understand what is really going on when your program is running. It is the x-ray of software development, allowing you to see inside programs and diagnose potential problems.
Without a debugger you are guessing; with a debugger you are seeing. It is as simple as that. Whatever time you invest in learning to use your debugger is time well spent.
The debugger is also a powerful tool for understanding code written by others. By putting someone else’s code into the debugger and stepping through it, you can see exactly how the methods work and what data they manipulate.
This book assumes you are working with Visual Studio .NET. The debugger we’ll investigate is the powerful symbolic debugger integrated within Visual Studio .NET.
The VS.NET debugger provides a number of windows for watching and interacting with your program while it executes. Getting comfortable with the debugger can make the difference between quickly finding bugs and struggling for hours or days.
Setting a Breakpoint
To get started with the debugger, return
to Example 9-1. Put a
breakpoint on the first line of Main() to see how this code actually works. A breakpoint is an instruction to the debugger to stop running. You set a breakpoint and then run the program and the debugger runs the program up until the breakpoint. Then you ...