遍历list<T>

来源:互联网 发布:观察者手机间谍软件 编辑:程序博客网 时间:2024/05/17 03:15
public static void ListGenericType(object list)
        {
            Type objType = list.GetType();
            int count = (int)(objType.GetProperty("Count").GetValue(list, null));
            for (int i = 0; i < count; i++)
            {
                object listItem = objType.GetProperty("Item").GetValue(list, new object[] { i });
                foreach (PropertyInfo propertyInfo in listItem.GetType().GetProperties())
                {
                    object value = propertyInfo.GetValue(listItem, null);
                    Console.WriteLine(propertyInfo.Name+"="+value);
                }
                
            }
        }
0 0
原创粉丝点击