我在字典类型集合上有以下循环
foreach(KeyValuePair<Vector2, Object> entry in v_map.map_set)
{
}
我想访问对象属性,但预期的语法不起作用。例如:
foreach(KeyValuePair<Vector2, Object> entry in v_map.map_set)
{
Object ob = entry.Value;
ob.property;
}
失败,因为 C# 找不到想要的属性。那么,如何访问所需的属性?
解决方案:
foreach(KeyValuePair<Vector2, Object> entry in v_map.map_set)
{
if (entry.Value is warehouse)
{
warehouse ob = (warehouse)entry.Value;
}
}