Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio format specifier for C# arrays?

In C++ I could do this, but I don't see how to do it in C#. Basically I want to use a format specifier in the Watch Window of my Visual Studio 2008 debugger to view only a slice or portion of an array. For example, if I have a 2D array like so:

int[,] myArray = new int[5,15]

I might only want to view the last 15 items in the list, so I would like to be able to put this into my watch window (or something similar):

myArray[5],15

Is there anything like this in Visual Studio?

like image 291
void.pointer Avatar asked Jul 07 '11 20:07

void.pointer


1 Answers

The format specifiers supported by Visual Studio 2008 debugger is described here. Clearly, the C# debugger does not support the same specifiers as C++.

Building on @Omers answer, you could watch a "processed" version of the array using the following watch expression:

System.Linq.Enumerable.Reverse(System.Linq.Enumerable.Take(System.Linq.Enumerable.Reverse(x), 2)), results

Note: the results format specifier is useful when watching IEnumerable results when you're interested in the results only.

like image 122
Peter Lillevold Avatar answered Sep 28 '22 08:09

Peter Lillevold