111,113
社区成员




static void GetModelList<T>(List<T> listT)
{
foreach (T p in listT)
{
}
}
static void Main()
{
//创建Person对象
TEST p1 = new TEST("张三", "1", 30);
TEST p2 = new TEST("李四", "2", 20);
TEST p3 = new TEST("王五", "3", 50);
//创建类型为Person的对象集合
List<TEST> persons = new List<TEST>();
//将Person对象放入集合
persons.Add(p1);
persons.Add(p2);
persons.Add(p3);
GetModelList<TEST>(persons);
}
foreach (T p in listT)
{
foreach (PropertyInfo pinfo in typeof(T).GetProperties())
{
Console.Write(pinfo.Name+":"+pinfo.GetValue(p, null));
Console.WriteLine();
}
}
获取值可以,但是你要返回对象就难了,所以你这个方法不靠谱static void GetModelList<T>(List<T> listT)
{
foreach (var p in listT)
{
}
}