Setting Your Watch
When you’re debugging a program with many local variables, you usually don’t want to watch all of them; you need to keep track of only a few. You can track specific variables and objects in the Watch window. You can have up to four Watch windows at a time in Visual Studio, but just the one in C# Express. 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-12. A Watch window lets you keep an eye on just the variables you want to track.
The Watch windows are usually tabbed with the Locals window. You can add a watch by right-clicking on a variable and choosing Add Watch or you can 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, you can right-click on it in the Watch list and select Delete Watch.
In Visual Studio only, 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access