遍历变量里面所有的属性

在开发中会遇到一个对象有大量的属性,这时候需要遍历。

            Studentdesc desc = new Studentdesc() 
            foreach (PropertyInfo p in desc.GetType().GetProperties())
            {
                Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(desc));
            }

这样,就可以得到信息喽。

原文地址:https://www.cnblogs.com/QQ544952425/p/2750096.html