首页 > Windows开发 > 详细

C# 遍历泛型集合

时间:2015-12-30 17:12:47      阅读:428      评论:0      收藏:0      [点我收藏+]

 

技术分享
 1     /// <summary>
 2         /// 遍历泛型
 3         /// </summary>
 4         /// <typeparam name="T"></typeparam>
 5         /// <param name="obj"></param>
 6         /// <returns></returns>
 7         public static List<T> Abcdefg<T>(List<T> obj)
 8         {
 9             foreach (T t in obj)
10             {
11                 if (t == null)
12                 {
13                     continue;
14                 }
15                 PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
16                 int length = myPropertyInfo.Length;
17                 for (int i = 0; i < length; i++)
18                 {
19                     PropertyInfo pi = myPropertyInfo[i];
20                     // 获取值
21                     pi.GetValue(t, null);
22                     // 修改值
23                     pi.SetValue(t, "要修改的值,但是必须保证与当前字段类型相同", null);
24 
25                 }
26             }
27             return obj;
28         }
View Code

 

C# 遍历泛型集合

原文:http://www.cnblogs.com/gaozejie/p/5089166.html

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