【发布时间】:2011-02-19 16:37:09
【问题描述】:
我有 3 个泛型类型列表。
List<Contact> = new List<Contact>();
List<Address> = new List<Address>();
List<Document> = new List<Document>();
并将其保存在类型为 object 的变量中。现在我需要做 Cast Back to List 来执行 foreach,有些是这样的:
List<Contact> = (List<Contact>)obj;
但 obj 内容每次都在变化,我有一些这样的:
List<???> = (List<???>)obj;
我有另一个变量保存当前的 obj 类型:
Type t = typeof(obj);
我可以这样做吗??:
List<t> = (List<t>)obj;
Obs:我没有列表中的当前类型,但我需要转换,我现在不需要另一种形式:
List<Contact> = new List<Contact>();
【问题讨论】: