C#遍历对象属性


 1 public void EachProperties()
 2 {
 3     Contract contract = new Contract { employeename = "Rikas" };
 4     Type type = contract.GetType();
 5     System.Reflection.PropertyInfo[] ps = type.GetProperties();
 6     foreach (PropertyInfo i in ps)
 7     {
 8     if (i.PropertyType == typeof(string))//属性的类型判断
 9     {
10         object obj = i.GetValue(contract, null);
11         string name = i.Name;
12     }
13     }
14 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM