遍历list

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);
                }
                
            }
        }

猜你喜欢

转载自blog.csdn.net/shixueli/article/details/51602531