Chapter 9. Basic Debugging

Mistakes happen. It’s a simple fact of life, and it’s true in programming, too. Even the most experienced programmers make mistakes, sometimes the same mistakes over and over. You’ve probably made a few as you’ve gone through the exercises in this book. Mistakes are normal, and they are easy to make, especially in a programming language such as C#; we even have a special word for programming mistakes: bugs. You’ve probably noticed that the compiler (that’s Visual Studio or C# Express) catches a lot of your bugs, and tells you what’s wrong. It’s even right a lot of the time, although it’s certainly not perfect. The more you learn, and the more you have the basics of the language down, the more complicated your mistakes become. Staring at the code and puzzling it out isn’t an effective way to find bugs anymore. For that, you need a debugger. Fortunately, Visual Studio (including C# Express) comes with a great debugger built right in.

The debugger is your friend. There is simply no tool more powerful than a debugger for learning C# and for writing quality C# programs. Put simply, the debugger is a tool that 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. ...

Get Learning C# 3.0 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.