Friday, January 15, 2010

Debugging IEnumerable

I often find enumerables difficult to inspect in the debugger. Here's a trick I just discovered.


IEnumerable foo = ...

you can inspect it more easily by first writing this in the Immediate Window:

foo = foo.ToList()

Press Enter in the immediate window, and foo changes from a (lazily) evaluated list (which is hard to inspect) into a real List which you can easily inspect by just hovering over it's Non-public members -> items.