Somewhere in my code I have an object that I already know that is a list. But I don't know the type parameter of that list. I need to iterate over it's items. I tried to cast that object to a list of objects but it didn't help me:
List<Object> objList = (List<Object>)(dataModel.Value);
foreach (var item in objList)
{
Console.WriteLine(item.ToString());
}
In the above code, the Value
property of dataModel
is a list of XYZ
values, but it throws an exception when I run this code. It says that, it could not cast XYZ
to Object
.
Is that possible to do some deserialization and do the job over deserialized objects?