StudentManager bll = new StudentManager();
object obj = bll.GetList();
IList list = obj as IList;
foreach (object item in list)
{
Type type = item.GetType();
foreach (PropertyInfo pi in type.GetProperties())
{
Console.Write(pi.GetValue(item, null));
}
Console.WriteLine();
}
public class StudentManager
{
List<Student> students = new List<Student>();
public StudentManager()
{
}
public List<Student> GetList()
{
students.Add(new Student(1, "gg"));
students.Add(new Student(2, "yy"));
return this.students;
}
}
public class Student
{
public Student(int id, string name)
{
this._id = id;
this._name = name;
}
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
1万+

被折叠的 条评论
为什么被折叠?



