C# 反射遍历对象

时间:2014-08-21 14:43:24   收藏:0   阅读:313

 

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

        /// <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(); ;

        }

 

C# 反射遍历对象,布布扣,bubuko.com

原文:http://www.cnblogs.com/PLifeCopyDown/p/3927027.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!