代码如下: 实体类: public class User implements Serializable { private static final long serialVersionUID = 1L; private String pkid; private String userName; private String passWord; private String roleID; } 遍历: public class test { public static void main(St
遍历获得一个实体类的所有属性名,以及该类的所有属性的值 //先定义一个类: public class User { public string name { get; set; } public string gender { get; set; } public string age { get; set; } } //实例化类,并给实列化对像的属性赋值: User u = new User(); u.name = "ahbool"; u.gender = "男"
一.引入 最近遇到一个项目里面的功能,在给实体类赋值的时候,由于赋值字段是动态生成的,所以如果用常用的方法(直接实体类的名称.字段名=要赋的值),将会生成很多无用的代码,所以找到了一个通过反射的赋值与取值的方法,顺便总结一下,以及对比一下与Python语言同样实现该功能的区别之处. 二.C# 1.赋值 2.取值 3.源码 using System; using System.Collections.Generic; using System.Linq; using System.Reflecti