我有一个列表的列表,每个列表都包含不同类别的对象。为了将元素添加到正确的列表中,我需要能够找到列表的类型。我目前正在尝试以以下方式实现:
foreach(object o in DataBase)
{
Type t = o.GetType();
if (t != typeof(T))
continue;
else
{
List<T> L = (List<T>)o;
L.Add(element);
break;
}
}
然而,这将返回一个List类型,格式为System.Collections.Generic.List`1[[myType,etc,etc]]。是否有一种方法从List的类型中提取出'myType',以进行正确的比较?