144Microsoft Visual Studio 2010: A Beginner’s Guide

Key Skills & Concepts

Exploring Available Debugging Tools

Setting Breakpoints

Inspecting Program State

Solving Problems with VS Debugging Tools

More often than we would like, our code has bugs. Fortunately, when bugs do happen, you have a lot of help with VS. This chapter shows you how to use the VS debugger

to fix problems by setting breakpoints, stepping through code, and inspecting program state. There’s also a section on development-time tools to inspect the structure of your code. Beyond setting breakpoints, you’ll learn how to customize breakpoints and how to manage a list of breakpoints. Then you’ll see the options VS has for stepping through code. This chapter also shows you many ways to see what the values of variables are in your code and the various tools available for inspecting your code. First, we’ll start with some example code you can use to practice the concepts learned in this chapter.

Example Code for This Chapter

It would take many pages of code to show a complete program with all of the complexity of a real-world scenario, which might be hard to follow for the purposes of this chapter. So, the example you’ll see simulates the environment of a full application. When performing debugging, you’ll need to traverse hierarchies in code, where one method calls another, which could go multiple levels deep, depending on the program. The example code will have multiple levels of method calls so that you can see how to use VS to debug code.

Listing 6-1 shows the example code for this chapter. It’s a console application, just like all of the applications created in previous chapters. You create a console project by selecting File New Project, select the Console Application project, give the project a name, and generate the project by clicking OK. The application in Listing 6-1 calculates a discount for a customer, based on a special discount percentage for that customer and what that customer ordered.

Page 167
Image 167
Microsoft 9GD00001 manual Example Code for This Chapter, Key Skills & Concepts