<p>I am writing an unit test for a mvc web application that checks if a returned list of anonymous variables(in a jsonresult) is correct. therefore i need to iterate through that list but i cannot seem to find a way to do so.</p>

<p>so i have 2 methods</p>

<p>1) returns a json result . In that json result there is a property called data. that property is of type object but internally it's a list of anonymous variables</p>

<p>2) the method calls method 1 and checks if the returned jsonresult is ok.</p>

<p>if i run the test and i break the debugger i can hover over the result and see the items in it. i just don't find a way to do so in code.(just using a foreach isn't possible because at the point i need it i'm not in the method that created the anonymous method)</p>

I think you mean "anonymous type" everywhere you've said "anonymous variable" - but you can still iterate over the list with
```
foreach
```
, just declaring the iteration variable as type
```
object
```
:
```
```
foreach (object o in myList)
{
    // Not sure what you're actually trying to do in here...
}
```
```
If you need to check the contents, you can use the fact that anonymous types override
```
ToString
```
in a useful way. Your test can check the result of projecting each element to a string. Indeed, you could convert your result object to a sequence of strings quite easily:
```
```
var strings = ((IEnumerable) result).Cast<object>.Select(x => x.ToString());
```
```
Then test
```
strings
```
possibly using
```
SequenceEqual
```
.