我想编写一个方法来搜索列表中的对象,该对象可以包含多个继承类型。
public class MyClass
{
public readonly List<parentType> objects = new List<parentType>();
public parentType GetObject(Type type, string tag)
{
foreach (parentType _object in objects)
{
if (_object.GetType() == type)
{
if (tag == _object.tag)
{
return _object;
}
}
}
return null;
}
}
但是当我打电话的时候
.GetObject(子类型,“标记”)
我得到CS0119:
“childType”是在给定上下文中无效的类型
。
我该怎么办?谢谢