BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Debugging
VS 2003+

Visual Studio Locals and Autos Windows

Visual Studio provides a large number of tools for use when debugging applications or stepping through code. Possibly the two most commonly used are the Locals and Autos windows, which allow variable values to be inspected and changed.

Debugging Windows

The Visual Studio Integrated Development Environment (IDE) provides many tools and windows that you can access whilst using the debugger. They allow you to monitor and control the flow of code in your program and to look at and change the values in variables at run-time. Two of the most commonly used debugging tools are the Locals and Autos windows. These are two similar but subtly different windows used for interrogating variable values.

Locals Window

The Locals window shows a grid containing all of the variables that are currently in scope. This includes variables that are declared within the method or property being debugged and those in its containing class or structure. The table includes one row for each variable, each with three columns of information, as shown below:

Visual Studio Locals Window

The Name column shows the name of each variable. This may be the name of the variable in the code or an alternative name provided by the DebuggerDisplay's Name parameter. For complex types an expansion button is provided, allowing you to expand and collapse a tree structure of all of the properties and fields contained within the object. This includes internal, protected and private elements.

The Value column shows the value of each item. If a DebuggerDisplay attribute has been applied to the type, the value will be determined by this attribute. For other items the text shown matches that generated by the value's ToString method. For some data types, a magnifying glass icon is displayed. You can see this for the testString variable in the above image. When clicked, various visualiser options are displayed to allow you to format the information and show it in a larger window. For example, string data can be visualised as text, XML or HTML.

The third column, "Type", shows the data type of each item. Usually this is the fully qualified class or structure name. However, this can be overridden using the DebuggerDisplay attribute's Type parameter.

If you cannot see the Locals window during debugging, open the Debug menu, expand the Windows submenu and choose "Locals".

Autos Window

The Autos window provides identical functionality to the Locals window but for a more focussed set of variables. The rows in the grid represent the values of variables in the current statement and the previous statement only. The current statement is the highlighted one that will be executed when you next step through the code. To view the Autos window choose "Autos" from the Windows submenu of the Debug menu.

Editing Values

Much of the time you will use the Locals and Autos windows to view the values of variables in order to identify problems with your code. Occasionally it can be useful to modify the values, perhaps when you are aware of a problem but wish to temporarily correct it in order to continue debugging. To modify a value, right-click it and choose "Edit Value" from the context-sensitive menu. You can now type a new value into the grid.

Hexadecimal Display

When integers are displayed in either window, they are shown using decimal. You can toggle between decimal and hexadecimal by right-clicking the grid and choosing the ""Hexadecimal Display" option from the menu. This setting is applied to all of the integers in the grid.

30 July 2011