I need to be able to loop around an unknown type for example
foreach (var test in viewData["foobar"])
{
}
Any suggestions
I need to be able to loop around an unknown type for example
foreach (var test in viewData["foobar"])
{
}
Any suggestions
You have to at least cast viewData["foobar"]
to IEnumerable
to have object
s in your test
variable.
The cast may fail, so you'll first have to check whether viewData["foobar"]
actually implements IEnumerable
with is
or as
operator:
if(viewData["foobar"] is IEnumerable)
foreach(var test in (IEnumerable)viewData["foobar"])
If viewData["foobar"]
is of the type object, then you can't iterate over it. The only way to iterate with a foreach loop is on IEnumerator derived types.