Section 9.3. Set Your Watch


9.3. Set Your Watch

When you're debugging a program with many local variables, you usually don't want to watch all of them; you only need to keep track of a few. You can track specific variables and objects in the Watch window . You can have up to four Watch windows at a time. Watch windows are like by- invitation versions of the Locals window; they list the objects you ask the debugger to keep an eye on, and you can see their values change as you step through the program, as illustrated in Figure 9-12.

Figure 9-11. Watching assignment

Figure 9-12. A Watch window

The Watch windows are usually tabbed with the Locals window. You can create more than one Watch window to organize the variables you keep an eye on, by selecting Watch 1 through Watch 4 from the Debug menu. You can add a watch by right-clicking on a variable and choosing Add Watch, or just drag the variable to the Watch window. The variable will be added to your Watch window. To remove a variable that you've added to your Watch window, right click on it in the Watch list, and select Delete.

If you just need to peek at a variable, and perhaps to experiment with manipulating its value, you can right-click on it and choose QuickWatch , which opens a dialog box with watch information about a single object, as shown in Figure 9-13.

You can enter any expression into the Expression field and evaluate it from within the QuickWatch window. For example, suppose you had integer variables named varOne and varTwo :

 int varOne = 5;     int varTwo = 7; 

Figure 9-13. QuickWatch window

If you want to know the impact of multiplying them, enter:

 varOne * varTwo 

into the Expression window and click Recalculate. The value is shown in the Value window, as in Figure 9-14.

Figure 9-14. QuickWatch recalculation

If you decide that you want to add the variable to a Watch window after all, click the Add Watch button.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net