码迷,mamicode.com
首页 > 其他好文 > 详细

遍历对象属性值

时间:2018-06-28 10:17:49      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:name   foreach   turn   app   har   rop   trim   null   build   

将对象内的属性以及属性值输出

   public static string ToProperties_V(this object obj)
        {
            if (obj == null) return "";
            var s = obj.GetType(); 
            StringBuilder app = new StringBuilder();
            foreach (var item in s.GetProperties())
            {
                app.Append($"{item.Name}:{item.GetValue(obj)}\n"); 
            }
            return app.ToString().Trim(‘,‘);
        }

  

遍历对象属性值

标签:name   foreach   turn   app   har   rop   trim   null   build   

原文地址:https://www.cnblogs.com/lsgControl/p/9237088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!