I want to iterate throug a Dictionary<string, object>
with a foreach
loop. First I get all of the items
with reflection. And when item.Name
is not settings
the program goes in the else
path. Here item
is of type Dictionary<string, object>
during runtime. But I get an error because at compile time item
is of type PropertyInfo
. Is it possible to loop over the Dictionary?
PropertyInfo[] propertyInfos = MyResponse.MyDocument.GetType().GetProperties();
foreach (var item in propertyInfos)
{
if (item.Name != "settings")
{
// do something
}
else
{
foreach (var setting in item) // Compiler Error CS1579
{
// do something else
}
}
}
Compiler Error CS1589 at Microsoft Learn
I’m using .NET Framework 4.5.