Difference between Autos and Locals Window in Visual Studio

Difference between Autos and Locals Window in Visual Studio

During debugging in Visual Studio most of the time we used Watch Window for inspect code. However we overlooked two additional debugging tools “Autos” and “Locals”  Window. These windows are tremendous helpful in some cases where you want to monitor your scope object during debugging. In this post, lets have a look what is the use of Autos and Locals windows and how they are differ.

Locals :

Locals windows automatically displays the list of variables and it’s values within the scope of current methods. If your debugger currently hits a particular breakpoint and if you open the “Locals” window, it will show you the current scope object variable along with the value.

Consider you have following code block running and you turned on the Locals Windows ( Debug –> Windows –> Locals), you should have able to see the following listed active objects with the values.

image

 

Keep in mind it will display the list of objects with values which are live within the current scope.  To understand it better, put a breakpoint inside the for loop and verify the Locals window once again,.

image

At this point, as “I” is an active object, that appear in the Locals Windows.

To summarize, the locals window shows everything which are currently in scope.

Autos :

These variables are also automatically detect by the Visual Studio debugger during the debugging. Visual Studio determines which objects or variables are important for the current code statement and based on that, it lists down the “Autos” variable.  Generally this shows the object in  current statement and the previous statement  with in that current scope.

Must Read / Related with Autos : Function return values inspection in Visual Studio

So if we open the Autos windows for previous code block execution, you will only see “I” and “temp” with in that.  Because, “I” is currently which is getting executed and “temp” was the previous statement.

image

 

All in all, the autos window is a subset of the locals window. When the local windows shows all the variable with in current scope, the Autos shows only the current and previously executed object’s value.

image

That’s it.

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.