在项目中需要遍历各种对象,可以通过如下方法遍历。

        /// <summary>
        /// 返回对象字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string ReturnString(object obj)
        {
            StringBuilder str = new StringBuilder();
            foreach (System.Reflection.PropertyInfo p in obj.GetType().GetProperties())
            {

                str.Append(string.Format("\tName:{0} Value:{1}\r\n", p.Name, p.GetValue(obj, null)));
            }

            return str.ToString(); ;

        }

 

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-10-27
  • 2021-05-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-12-07
相关资源
相似解决方案