我们可以按照下面的步骤返回集合类的值
1. 确认对象是泛型对象
if (myList.GetType().IsGenericType)
2. 返回Count属性检查列表的元素数量
int n = (int)myList.GetType().GetProperty("Count").GetValue(myList, null);
3. 对泛型对象的每个元素循环调用GetValue()方法
//遍历列表的每个元素
for (int i = 0; i < n; i++)
{
// 获得列表元素的类型对象
object[] index = { i };
object myObject = myList.GetType().GetProperty("Item").GetValue(myList, index);
}
更多的细节代码示例,请参阅相关的帖子:
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/4d310108-ca7c-47de-b5bd-962dfc88ed92/
如果您对我们的论坛在线支持服务有任何的意见或建议,请通过
邮件告诉我们。
立刻免费下载
MSDN 论坛好帮手