You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/debugger/autos-and-locals-windows.md
+58-55Lines changed: 58 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Inspect variables - Visual Studio debugger
3
3
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.
# Inspect variables and return values in the Visual Studio debugger
20
20
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 are 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.
22
22
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 youhow 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:
24
24
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, view data tips and inline return values
26
+
- View variables in debugger windows (Autos, Locals, and Watch windows)
27
+
- Opne visualizers for large strings or complex .NET objects
29
28
30
29
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).
31
30
32
31
> [!NOTE]
33
32
> 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.
34
33
34
+
## View data tips in the code editor
35
+
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
+

42
+
::: moniker-end
43
+
::: moniker range="<= vs-2019"
44
+

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 is not 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
+
[](../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
+
[](../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 and choose **Add Watch**.
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).
79
+
80
+
For detailed information, see [Set a Watch using the Watch and QuickWatch Windows](../debugger/watch-and-quickwatch-windows.md).
81
+
35
82
## Inspect variables in the Autos and Locals windows
36
83
37
84
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.
@@ -168,51 +215,7 @@ Different code languages display different variables in the **Autos** window.
168
215
169
216
The variable `e` is uninitialized, because the line `e = 5` has not yet been executed.
170
217
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
-

179
-
::: moniker-end
180
-
::: moniker range="<= vs-2019"
181
-

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**.
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
-
[  ](../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
-
[  ](../debugger/media/vs-2022/view-return-values-copilot.png#lightbox)
213
-
::: moniker-end
214
-
215
-
### View return values in the Autos windows
218
+
### View return values in the Autos window
216
219
217
220
In the following example, this C# code adds the return values of two functions:
218
221
@@ -251,14 +254,14 @@ To see the return values of the `sumVars()` and `subtractVars()` method calls in
251
254

252
255
::: moniker-end
253
256
254
-
## Inspect variables in a visualizer
257
+
## Open a visualizer to inspect variables
255
258
256
259
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:
257
260
258
261
- 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).
259
262
- 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.
260
263
261
-
The visualizers appear in the **Autos** windows and other debugger windows.
264
+
The visualizers appear in the **Autos** windows, data tips, and other debugger windows.
262
265
263
266
> [!NOTE]
264
267
> 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).
0 commit comments