C# – Look at the Variables’ Values, while Debugging in Visual Studio

Debugging is like being the detective in a crime movie where you are also the murderer.

In order to debug well, we need to know the value of the current variable. In Visual Studio, this could be acquired through multiple ways. Here are some of them:

Auto Window

The auto window simply returns the variables 3 lines behind and 1 line in front of the current line. Sometimes the lines vary:

Shortcut:
Ctrl+Alt+V, A

Local Window

The local window returns all the variables in the current method. If a value is changed, it is highlighted in red:


Shortcut:
Ctrl+Alt+V, L

Watch Window

The watch window starts without any variables in it, but these could be added, either by manually writing them or by selecting the variable in the code and with the mouse menu clicking “Add to Watch”. Additionally, whole methods could be evaluated there, with parameters taken from the code as in the example NPlusCounter:


Shortcut:
Ctrl+Alt+W, 1(or 2,3,4)

Tagged with: , , , ,