3

Visual Studio 2005 allows you to add a watch on particular elements of a list. For example, let's say we have a class like this:

class Foo
{
  string name;
  int x;
  int y;
}

And then we declare:

List<Foo> foos = new List<Foo>();

... and it fills up with thousands of elements. I know that it is possible to add a watch on the expressions foos[1].x or foos[i].x. What I would like to know is whether I can add a watch on foos[all].x so that my watch window will automatically look like this:

foos[0].x = 1
foos[1].x = 2
// ...
foos[foos.Count-1].x = 42

This would save a great deal of time in allowing me to visualize the contents of my list. Does VS2005 or one of its plugins have a way to accomplish this? How about VS2010?

Andrew Orsich
  • 52,935
  • 16
  • 139
  • 134
David
  • 1,187
  • 1
  • 10
  • 22

2 Answers2

2

how about "object dumper" ?

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/25/all-about-objectdumper.aspx

or

C# object dumper

Community
  • 1
  • 1
Old Programmer
  • 546
  • 1
  • 4
  • 17
2

There is 'watch' window, inside of that you can add any watch variable that you want. Also check that article that i quickly found in google.

For dynamic watch you can use Debug.Print:

for example :

 for (int i = 0; i < foos.Count(); i++)
 {
    Debug.Print("foos[{0}].x={1}",i,foos[i].x);
 }
Andrew Orsich
  • 52,935
  • 16
  • 139
  • 134
  • I know about the watch window. My question was asking whether you can programmatically add a watch for foos[i].x, for all i, without knowing how many items are in the list. – David Dec 14 '10 at 14:40