C#遍历匿名对象的所有属性、value

Object obj = new { name="admin",age=123 ,pwd="123" };
//遍历匿名对象
foreach (System.Reflection.PropertyInfo p in obj.GetType().GetProperties())
{
    Console.WriteLine("name:{0},value:{1}",p.Name,p.GetValue(obj));
}

 

posted @ 2017-11-04 18:01  fight139  阅读(2509)  评论(0编辑  收藏  举报