当前位置: 移动技术网 > IT编程>开发语言>c# > 自动输出类的字段值实用代码分享

自动输出类的字段值实用代码分享

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:using system;using system.linq;using system.reflection; namespace lucienbao

复制代码 代码如下:

using system;
using system.linq;
using system.reflection;

namespace lucienbao.common
{
    public static class tostringhelper
    {
        public static string tostring(object obj)
        {
            type t = obj.gettype();
            fieldinfo[] fis = t.getfields();
            return string.join(environment.newline,
                                fis.select<fieldinfo, string>
                                    (p => p.name + ":" + p.getvalue(obj).tostring()).toarray()
                                );
        }
    }
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网