开发者

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开发者_Go百科 something similar):

myArray[5],15

Is there anything like this in Visual Studio?


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.


This doesn't directly answer your question, but if you have System.Core loaded, and a using System.Linq; in your scope, you could just evaluate myArray[5].Reverse().Take(5).Reverse() to get the last 5 values.


Check this out. This VS plugin increases the number of ways you can visualize data in debug mode.

http://karlshifflett.wordpress.com/mole-2010/

... there is a 2008 version as well

http://karlshifflett.wordpress.com/mole-2010/mole-for-visual-studio/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜