15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

398 ❘ ChaPTer 16 visuAl studiO 2010<br />

In general, it is not that often that you will need to adjust the configuration settings. However, if you ever do<br />

need to use them, you now know the difference between the available configuration properties.<br />

figure 16-24<br />

debugging your Code<br />

After the long discussion about building <strong>and</strong> build configurations, you might be surprised to learn that this<br />

chapter is not going to spend a great deal of time discussing debugging itself. The reason for that is that the<br />

principles <strong>and</strong> the process of debugging — setting breakpoints <strong>and</strong> examining the values of variables — is<br />

not really significantly different in Visual Studio from any of the various Visual Studio 6 IDEs. Instead, this<br />

section briefly reviews the features offered by Visual Studio, focusing on those areas that might be new to<br />

some developers. It also discusses how to deal with exceptions, because these can cause problems during<br />

debugging.<br />

In <strong>C#</strong>, as in pre-.<strong>NET</strong> languages, the main technique involved in debugging is simply setting breakpoints<br />

<strong>and</strong> using them to examine what is going on in your code at a certain point in its execution.<br />

Breakpoints<br />

You can set breakpoints from Visual Studio on any line of your code that is actually executed. The simplest<br />

way is to click the line in the code editor, within the shaded area toward the far left of the document window<br />

(or press the F9 key when the appropriate line is selected). This sets up a breakpoint on that particular line,<br />

which causes execution to break <strong>and</strong> control to be transferred to the debugger as soon as that line is reached<br />

in the execution process. As in previous versions of Visual Studio, a breakpoint is indicated by a large circle<br />

to the left of the line in the code editor. Visual Studio also highlights the line by displaying the text <strong>and</strong><br />

background in a different color. Clicking the circle again removes the breakpoint.<br />

If breaking every time at a particular line is not adequate for your particular problem, you can also set<br />

conditional breakpoints. To do this, select Debug ➪ Windows ➪ Breakpoints. This brings up a dialog box<br />

asking you for details of the breakpoint you want to set. Among the options available, you can:<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!