Debugging in Visual Studio .NET

The easiest and best way to avoid bugs is to let Visual Studio .NET help you find and remove them.

When you run your code in the debugger, you can literally watch your code progress, step by step. As you walk through the code, you can see the variables change values and watch as objects are created and destroyed. A good symbolic debugger is like a full motion CAT scan of your program.

The debugger is one of the most powerful tools at your disposal for learning Windows programming. This section provides a brief introduction to the most important parts of the debugger within Visual Studio .NET. For complete coverage of the Visual Studio .NET debugger, please see Mastering Visual Studio .NET by Ian Griffiths (O'Reilly).

Finding Syntax Errors

Your eye tends to see what it expects. For example, read the sentence in Figure 21-3.

Seeing what you expect

Figure 21-3. Seeing what you expect

Many readers will see this as "Paris in the spring" even after reading it a few times. Some readers will see the mistake only when they actually place their index fingers on the page and mark off each word. The brain tends to see what it expects to see, and finding syntax errors can be terribly difficult. Fortunately, this is the easiest kind of error for Visual Studio .NET to find.

Consider the following C# code that will not compile:

private void mnuStartLoop_Click(object sender, System.EventArgs ...

Get Programming .NET Windows Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.