首页 > 其他 > 详细

开发日记

时间:2017-03-13 13:15:00      阅读:191      评论:0      收藏:0      [点我收藏+]

c# 遍历对象属性给对象赋值

TJlb_Mod tJlb = new TJlb_Mod();

tJlb.GetType().GetProperty("FNo").SetValue(tJlb, 11);

 

  1.  System.Reflection.PropertyInfo[] properties = tJlb.GetType().GetProperties();  
  2.             foreach (System.Reflection.PropertyInfo property in properties)  
  3.             {  
  4.                 string name=property.Name;  
  5.                 string value = property.GetValue(tJlb).ToString();  
  6.             }  
  7.         /// <summary>  
  8.         /// 通过遍历属性赋值  
  9.         /// </summary>  
  10.         /// <returns></returns>  
  11.         private Values SetValues()  
  12.         {  
  13.             System.Reflection.PropertyInfo[] properties = tJlb.GetType().GetProperties();  
  14.             for (int i = 0; i < properties.Length; i++)  
  15.             {  
  16.                 properties[i].SetValue(tJlb, (i + 1));  
  17.             } 

开发日记

原文:http://www.cnblogs.com/sky-gfan/p/6541932.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!