views:

2443

answers:

3

Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array.

+18  A: 

You can try this nice little trick for C++. Take the expression which gives you the array and then append a comma and the number of elements you want to see. Expanding that value will show you elements 0-(N-1) where N is the number you add after the comma.

For example if "pArray" is the array, type "pArray,10" in the watch window.

JaredPar
This is soooo ridiculously hard to figure out by oneself, exceptionally useful and easy to achieve.
Sergej Andrejev
+1  A: 

Hover your mouse cursor over the name of the array, then hover over the little (+) icon that appears.

RichieHindle
For C++ this will only show you the first element
JaredPar
Actually VS 2008 does expand the array after you hover over the +
John Weldon
Hmm; stanigator clarified this point... apologies to JaredPar
John Weldon
@John, no worries
JaredPar
+4  A: 

Are you trying to view an array with memory allocated dynamically? If not, you can view an array for C++ and C# by putting it in the watch window in the debugger, with its contents visible when you expand the array on the little (+) in the watch window by a left mouse-click.

If it's a pointer to a dynamically allocated array, to view N contents of the pointer, type "pointer, N" in the watch window of the debugger. Note, N must be an integer or the debugger will give you an error saying it can't access the contents. Then, left click on the little (+) icon that appears to view the contents.

stanigator