比如我现在有一个Student的对象,里面有属性stuName,stuAge,stuGender,我现在该怎么写循环才能遍历这几个属性?
Student s=new......
foreach (System.Reflection.PropertyInfo p in s.GetType().GetProperties())
{
Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(s));
}
比如我现在有一个Student的对象,里面有属性stuName,stuAge,stuGender,我现在该怎么写循环才能遍历这几个属性?
Student s=new......
foreach (System.Reflection.PropertyInfo p in s.GetType().GetProperties())
{
Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(s));
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。