简体   繁体   中英

Visual Studio debugging - Order of local variables?

I am wondering on what concept/logic the ordering of the variables is based on in the 'Locals' tab when debugging an application with MS Visual Studio. For me it seems to be somewhat randomly ordered? Or is there any concept behind the ordering of these variables?

Is there an option to sort these variables alphabetically? This would be very handy.

I don't know a way to sort the items in the locals tab directly. But here is a workaround:

  1. Select all locals (Ctrl-A, Ctrl-C) and paste them to a watch list (Ctrl-V).
  2. Sort the watch list by (workaround again) cut and pasting them.

Note that there is an "Autos" watch window. Maybe it's better suited for your needs, although you neither can sort entries there.

Finally you may have more than one (custom) watch window, see Menu / Debug / Window / Watch / Watch 1 .. 4. This may also be helpful organizing variables to watch.

In my Visual Studio 2008, the sort order of Locals window is as follows: the current class-level Me object is first, with any module-level variables being sub-nodes of that. Then listed below Me are the procedure-level variables in Alphabetical order. After years of searching, I haven't found any way to change the sort order. The only thing left I can think of is a Visual Studio Extensibility Add-In, but I haven't explored that.

I have a strong background in VBA, and I can tell you over there, if there's a Me object in the current context, that comes first just like Visual Studio. But... and here's the difference ...the module-level variables are listed in Declaration Order , meaning they're listed in the same order as their Dim statements. And just like Visual Studio, the order can't be changed.

The VBA way of doing it is much more useful, because you can control the order of the Locals window by re-ordering the Dim statements in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM