Skip to content

Commit cb025ff

Browse files
authored
Merge pull request #13814 from Mikejo5000/mikejo-br25
Refactor article on variable inspection
2 parents e91e4e5 + 25c8a15 commit cb025ff

File tree

2 files changed

+76
-73
lines changed

2 files changed

+76
-73
lines changed

docs/debugger/autos-and-locals-windows.md

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Inspect variables - Visual Studio debugger
33
description: Inspect variables in the Autos and Locals windows while debugging in Visual Studio. The Autos and Locals windows show variable values while you are debugging.
4-
ms.date: 3/11/2025
4+
ms.date: 4/10/2025
55
ms.topic: how-to
66
f1_keywords:
77
- vs.debug.autos
@@ -16,33 +16,86 @@ ms.subservice: debug-diagnostics
1616
ms.collection: ce-skilling-ai-copilot
1717
---
1818

19-
# Inspect variables in the Visual Studio debugger
19+
# Inspect variables and return values in the Visual Studio debugger
2020

21-
Features that allow you to inspect variables are some of the most useful features of the debugger, and there are different ways to do it. Often, when you try to debug an issue, you are attempting to find out whether variables are storing the values that you expect them to have in a particular app state.
21+
When you try to debug an issue, you're often attempting to find out whether variables are storing the values that you expect them to have in a particular app state. Some of the most useful features of the debugger are those that allow you to inspect variables.
2222

23-
In this article, you'll learn how to inspect variables using the debugger in Visual Studio. The Visual Studio debugger provides several convenient ways to view variable values while debugging, including the following:
23+
This article shows you how to inspect variables and view return values using the debugger in Visual Studio. The debugger provides several convenient ways to perform these tasks, including the following:
2424

25-
- Variable inspection windows (Autos, Locals, and Watch windows)
26-
- Data tips in the code editor
27-
- Inline return values
28-
- Visualizers for large strings or complex .NET objects
25+
- In the code editor, you can view data tips and inline return values
26+
- In debugger windows (Autos, Locals, and Watch windows), you can view variable values
27+
- In visualizers, you can view large strings or complex .NET objects
2928

3029
These features are only available while debugging. To learn how to start a debugging session, see [Start debugging and enter break mode](../debugger/navigating-through-code-with-the-debugger.md#start-debugging-and-enter-break-mode).
3130

3231
> [!NOTE]
3332
> If this is the first time that you've tried to debug code, you might want to read [Debugging for absolute beginners](../debugger/debugging-absolute-beginners.md) and [Debugging techniques and tools](../debugger/write-better-code-with-visual-studio.md) before going through this article.
3433
35-
## Inspect variables in the Autos and Locals windows
34+
## View variables in the code editor
3635

37-
The **Autos** and **Locals** windows show variable values while you are debugging. The windows are only available during a debugging session. The **Autos** window shows variables used around the current statement where the debugger is paused. The **Locals** window shows variables defined in the local scope, which is usually the current function or method.
36+
Often, when debugging, you want a quick way to check property values on objects in the code editor, and the data tips are a good way to do it.
37+
38+
While paused in the debugger, hover over an object with the mouse and you see its value, or its default property value.
39+
40+
::: moniker range=">= vs-2022"
41+
![View a Data Tip](../debugger/media/vs-2022/dbg-tour-data-tips.png "View a data tip")
42+
::: moniker-end
43+
::: moniker range="<= vs-2019"
44+
![View a Data Tip](../debugger/media/dbg-tour-data-tips.gif "View a data tip")
45+
::: moniker-end
46+
47+
If the variable has properties, you can expand the object to see all its properties.
48+
49+
For detailed information on using data tips, see [View data values in data tips](../debugger/view-data-values-in-data-tips-in-the-code-editor.md).
50+
51+
::: moniker range=">= vs-2022"
52+
## View inline return values of method calls in the code editor
53+
54+
In .NET and C++ code, you can examine return values when you step over or out of a method call, which can be useful when the return value isn't stored in a local variable. A method could be used as a parameter, or as the return value of another method.
55+
56+
Starting in Visual Studio 2022 version 17.12, you can view return values of method calls inline and not just in the [Autos window](#view-return-values-in-the-autos-window).
57+
58+
[ ![Screenshot showing the return values of method calls.](../debugger/media/vs-2022/view-return-values.png) ](../debugger/media/vs-2022/view-return-values.png#lightbox)
59+
60+
With Copilot enabled, you can also get targeted assistance related to the inline return value by using the Ask Copilot button that appears in the data tip for the return value.
61+
62+
[ ![Screenshot showing the return values of method calls with Copilot icon.](../debugger/media/vs-2022/view-return-values-copilot.png) ](../debugger/media/vs-2022/view-return-values-copilot.png#lightbox)
63+
::: moniker-end
64+
65+
## Set a watch on variables
66+
67+
You can use a **Watch** window to specify a variable (or an expression) that you want to keep an eye on.
68+
69+
While debugging, right-click an object in the code editor and choose **Add Watch**. A Watch window opens.
70+
71+
::: moniker range=">= vs-2022"
72+
![Watch Window](../debugger/media/vs-2022/dbg-tour-watch-window.png "Watch window")
73+
::: moniker-end
74+
::: moniker range="<= vs-2019"
75+
![Watch Window](../debugger/media/dbg-tour-watch-window.png "Watch window")
76+
::: moniker-end
77+
78+
In this example, you've a watch set on the object, and you can see its value change as you move through the debugger. Unlike the other variable windows, the **Watch** windows always show the variables that you're watching (they're grayed out when out of scope).
79+
80+
For detailed information, see [Set a Watch using the Watch and QuickWatch Windows](../debugger/watch-and-quickwatch-windows.md).
81+
82+
::: moniker range=">= vs-2022"
83+
## Get AI assistance
84+
85+
If you have [Copilot](../ide/visual-studio-github-copilot-extension.md), you can get AI assistance while you're looking at variables in the code editor or in the Autos or Locals windows. While you're debugging, right-click on a variable and use the **Ask Copilot** ![Screenshot of Ask Copilot button.](../debugger/media/vs-2022/debug-with-copilot-ask-copilot-button.png) button. In this scenario, Copilot already knows the context for your question, so you don't need to provide context yourself in chat. For more information, see [Debug with Copilot](../debugger/debug-with-copilot.md).
86+
::: moniker-end
87+
88+
## Inspect variables in debugger windows (Autos and Locals)
89+
90+
The **Autos** and **Locals** windows show variable values while you're debugging. The windows are only available during a debugging session. The **Autos** window shows variables used around the current statement where the debugger is paused. The **Locals** window shows variables defined in the local scope, which is usually the current function or method.
3891

3992
- To open the **Autos** window, while debugging, select **Debug** > **Windows** > **Autos**, or press **Ctrl**+**Alt**+**V** > **A**.
4093

4194
The **Autos** window is available for C#, Visual Basic, C++, and Python code, but not for JavaScript or F#.
4295

4396
- To open the **Locals** window, while debugging, select **Debug** > **Windows** > **Locals**, or press **Alt**+**4**.
4497

45-
Arrays and objects show in the **Autos** and **Locals** windows as tree controls. Select the arrow to the left of a variable name to expand the view to show fields and properties. Here is an example of a <xref:System.IO.FileStream?displayProperty=fullName> object in the **Locals** window:
98+
Expandable arrays and objects show up in the **Autos** and **Locals** windows. Select the arrow to the left of a variable name to expand the view to show fields and properties. Here is an example of a <xref:System.IO.FileStream?displayProperty=fullName> object in the **Locals** window:
4699

47100
::: moniker range=">= vs-2022"
48101
![Screenshot of the Locals window, with file set to a System.IO.FileStream value.](../debugger/media/vs-2022/locals-filestream.png)
@@ -55,7 +108,7 @@ A red value in the **Locals** or **Autos** window means the value has changed si
55108

56109
The default numeric format in debugger windows is decimal. To change it to hexadecimal, right-click in the **Locals** or **Autos** window and select **Hexadecimal Display**. This change affects all debugger windows.
57110

58-
### Edit variable values in the Autos or Locals window
111+
## Edit variable values in the Autos or Locals window
59112

60113
To edit the values of most variables in the **Autos** or **Locals** windows, double-click the value and enter the new value.
61114

@@ -66,11 +119,11 @@ In native C++ code, you might have to qualify the context of a variable name. Fo
66119
>[!CAUTION]
67120
> Make sure you understand the consequences before you change values and expressions. Some possible issues are:
68121
>
69-
>- Evaluating some expressions can change the value of a variable or otherwise affect the state of your program. For example, evaluating `var1 = ++var2` changes the value of both `var1` and `var2`. These expressions are said to have [side effects](https://en.wikipedia.org/wiki/Side_effect_\(computer_science\)). Side effects can cause unexpected results if you are not aware of them.
122+
>- Evaluating some expressions can change the value of a variable or otherwise affect the state of your program. For example, evaluating `var1 = ++var2` changes the value of both `var1` and `var2`. These expressions are said to have [side effects](https://en.wikipedia.org/wiki/Side_effect_\(computer_science\)). Side effects can cause unexpected results if you're not aware of them.
70123
>
71124
>- Editing floating-point values can result in minor inaccuracies because of decimal-to-binary conversion of fractional components. Even a seemingly harmless edit can result in changes to some of the bits in the floating-point variable.
72125
73-
### Search in the Autos or Locals window
126+
## Search in the Autos or Locals window
74127

75128
You can search for keywords in the Name, Value, and Type columns of the **Autos** or **Locals** window using the search bar above each window. Hit ENTER or select one of the arrows to execute a search. To cancel an ongoing search, select the "x" icon in the search bar.
76129

@@ -85,7 +138,7 @@ Use the left and right arrows (Shift+F3 and F3, respectively) to navigate betwee
85138

86139
To make your search more or less thorough, use the **Search Deeper** dropdown list at the top of the **Autos** or **Locals** window to select how many levels deep you want to search into nested objects.
87140

88-
### Pin properties in the Autos or Locals window
141+
## Pin properties in the Autos or Locals window
89142

90143
> [!NOTE]
91144
> This feature is supported for .NET Core 3.0 or higher.
@@ -100,7 +153,7 @@ You can also toggle property names and filter out non-pinned properties when vie
100153

101154
![Screenshot of Toggle property names.](../debugger/media/toggle-property-names.gif "Toggle property names")
102155

103-
### Change the context for the Autos or Locals window
156+
## Change the context for the Autos or Locals window
104157

105158
You can use the **Debug Location** toolbar to select a desired function, thread, or process, which changes the context for the **Autos** and **Locals** windows.
106159

@@ -115,7 +168,7 @@ Set a breakpoint and start debugging. When the breakpoint is hit, execution paus
115168
![Screenshot of Debug Location toolbar.](../debugger/media/debuglocationtoolbar.png "Debug Location toolbar")
116169
::: moniker-end
117170

118-
### <a name="bkmk_whatvariables"></a> Language differences in the Autos window (C#, C++, Visual Basic, Python)
171+
## <a name="bkmk_whatvariables"></a> Language differences in the Autos window (C#, C++, Visual Basic, Python)
119172

120173
Different code languages display different variables in the **Autos** window.
121174

@@ -168,51 +221,7 @@ Different code languages display different variables in the **Autos** window.
168221
169222
The variable `e` is uninitialized, because the line `e = 5` has not yet been executed.
170223
171-
## View data tips
172-
173-
Often, when debugging, you want a quick way to check property values on objects in the code editor, and the data tips are a good way to do it. For detailed information on using data tips, see [View data values in data tips](../debugger/view-data-values-in-data-tips-in-the-code-editor.md).
174-
175-
While paused in the debugger, hover over an object with the mouse and you see its value, or its default property value.
176-
177-
::: moniker range=">= vs-2022"
178-
![View a Data Tip](../debugger/media/vs-2022/dbg-tour-data-tips.png "View a data tip")
179-
::: moniker-end
180-
::: moniker range="<= vs-2019"
181-
![View a Data Tip](../debugger/media/dbg-tour-data-tips.gif "View a data tip")
182-
::: moniker-end
183-
184-
If the variable has properties, you can expand the object to see all its properties.
185-
186-
## Set a watch on variables
187-
188-
You can use a **Watch** window to specify a variable (or an expression) that you want to keep an eye on. For detailed information, see [Set a Watch using the Watch and QuickWatch Windows](../debugger/watch-and-quickwatch-windows.md).
189-
190-
While debugging, right-click an object and choose **Add Watch**.
191-
192-
::: moniker range=">= vs-2022"
193-
![Watch Window](../debugger/media/vs-2022/dbg-tour-watch-window.png "Watch window")
194-
::: moniker-end
195-
::: moniker range="<= vs-2019"
196-
![Watch Window](../debugger/media/dbg-tour-watch-window.png "Watch window")
197-
::: moniker-end
198-
199-
In this example, you have a watch set on the object, and you can see its value change as you move through the debugger. Unlike the other variable windows, the **Watch** windows always show the variables that you are watching (they're grayed out when out of scope).
200-
201-
## View return values of method calls
202-
203-
In .NET and C++ code, you can examine return values in the **Autos** window when you step over or out of a method call, which can be useful when the return value is not stored in a local variable. A method could be used as a parameter, or as the return value of another method.
204-
205-
::: moniker range=">= vs-2022"
206-
Starting in Visual Studio 2022 version 17.12 Preview 3, you can also view return values of method calls inline and not just in the Autos window.
207-
208-
[ ![Screenshot showing the return values of method calls.](../debugger/media/vs-2022/view-return-values.png) ](../debugger/media/vs-2022/view-return-values.png#lightbox)
209-
210-
With Copilot enabled, you can also get targeted assistance related to the inline return value by using the Ask Copilot button that appears in the data tip for the return value.
211-
212-
[ ![Screenshot showing the return values of method calls with Copilot icon.](../debugger/media/vs-2022/view-return-values-copilot.png) ](../debugger/media/vs-2022/view-return-values-copilot.png#lightbox)
213-
::: moniker-end
214-
215-
### View return values in the Autos windows
224+
## View return values in the Autos window
216225
217226
In the following example, this C# code adds the return values of two functions:
218227
@@ -251,14 +260,14 @@ To see the return values of the `sumVars()` and `subtractVars()` method calls in
251260
![Screenshot of Autos return value C#.](../debugger/media/autosreturnvaluecsharp2.png "Autos return value C#")
252261
::: moniker-end
253262

254-
## Inspect variables in a visualizer
263+
## Open a visualizer to inspect variables
255264

256-
While you are debugging in Visual Studio, you can view large strings or complex objects with built-in visualizers that make the data easier to inspect. For example:
265+
While you're debugging in Visual Studio, you can view large strings or complex objects with built-in visualizers that make the data easier to inspect. For example:
257266

258267
- The string visualizer shows text, XML, HTML, and JSON strings that are too long for a data tip or debugger window. It can also help you identify malformed strings. For more information, see [View strings in a string visualizer](../debugger/view-strings-visualizer.md).
259268
- The DataSet and IEnumerable visualizers show .NET collection objects in a tabular visualizer. For more information, see [Tabular visualizers in Visual Studio](../debugger/view-data-in-tabular-visualizer.md)) objects.
260269

261-
The visualizers appear in the **Autos** windows and other debugger windows.
270+
The visualizers appear in the **Autos** windows, data tips, and other debugger windows.
262271

263272
> [!NOTE]
264273
> If you need to inspect XAML or WPF UI elements in a visualizer, see or [Inspect XAML properties while debugging](../xaml-tools/inspect-xaml-properties-while-debugging.md) or [How to use the WPF tree visualizer](../debugger/how-to-use-the-wpf-tree-visualizer.md).
@@ -272,12 +281,6 @@ To open a visualizer, you must be paused during debugging. Hover over a variable
272281
![Open a string visualizer](../debugger/media/dbg-tips-string-visualizers.png "Open string visualizer")
273282
::: moniker-end
274283

275-
::: moniker range=">= vs-2022"
276-
## Get AI assistance
277-
278-
If you have [Copilot](../ide/visual-studio-github-copilot-extension.md), you can get AI assistance while you're looking at variables in the Autos or Locals windows, or in data tips. Right-click on a variable and use the **Ask Copilot** ![Screenshot of Ask Copilot button.](../debugger/media/vs-2022/debug-with-copilot-ask-copilot-button.png) button. In this scenario, Copilot already knows the context for your question, so you don't need to provide context yourself in chat. For more information, see [Debug with Copilot](../debugger/debug-with-copilot.md).
279-
::: moniker-end
280-
281284
## Related content
282285

283286
- [What is debugging?](../debugger/what-is-debugging.md)

docs/debugger/debug-with-copilot.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ In addition, Copilot provides more precise help for some targeted scenarios, suc
222222
|Conditional breakpoints and tracepoints|See [Get suggestions with conditional breakpoints and tracepoints](#get-suggestions-with-conditional-breakpoints-and-tracepoints) in this article.|
223223
|Quick Actions (light bulb)|See [Get AI assistance with Quick Actions](../ide/quick-actions.md#get-ai-assistance).|
224224
|IEnumerable tabular visualizer|See [Modify the visualizer expression](../debugger/view-data-in-tabular-visualizer.md#modify-the-expression-in-the-ienumerable-visualizer).|
225-
|Inline return values|See [View return values of method calls](../debugger/autos-and-locals-windows.md#view-return-values-of-method-calls).|
225+
|Inline return values|See [View return values of method calls](../debugger/autos-and-locals-windows.md#view-inline-return-values-of-method-calls-in-the-code-editor).|
226226
|Summary thread descriptions|See [Threads View (Parallel Stacks)](../debugger/using-the-parallel-stacks-window.md#threads-view).|
227227
|Auto insights for profiling|See [Get AI assistance with Auto insights](../profiling/cpu-insights.md#get-ai-assistance).|
228228

229-
In most of these scenarios, you get targeted assistance by using the **Ask Copilot** ![Screenshot of Ask Copilot button.](../debugger/media/vs-2022/debug-with-copilot-ask-copilot-button.png) button. Copilot already knows the context for your questions. For example, it knows the current call stack, the code line you are asking about, and the name of the exception (if one occurred), so you don't need to provide context yourself in chat. Copilot also provides suggestions for the use of conditional breakpoints and tracepoints.
229+
In most of these scenarios, you get targeted assistance by using the **Ask Copilot** ![Screenshot of Ask Copilot button.](../debugger/media/vs-2022/debug-with-copilot-ask-copilot-button.png) button. Copilot already knows the context for your questions. For example, it knows the current call stack, the code line you're asking about, and the name of the exception (if one occurred), so you don't need to provide context yourself in chat. Copilot also provides suggestions for the use of conditional breakpoints and tracepoints.

0 commit comments

Comments
 (0)