C#迭代器

 1.C#获取object对象属性值

object对象属性值获取
 1 private void button3_Click(object sender, EventArgs e)
 2         {
 3             xlsCell cel=new xlsCell(1,100);
 4             List<object> lis=GetPropertyValue(cel);
 5             string s=string.Empty;
 6             foreach (object o in lis)
 7             {
 8                 s += string.Format("_{0}", o.ToString());
 9             }
10             MessageBox.Show(s);
11         }
12 
13         public static List<object> GetPropertyValue(object info)
14         {
15             List<object> list = new List<object>();
16             if (info == null) return null;
17             Type t = info.GetType();
18             //IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
19             IEnumerable<System.Reflection.PropertyInfo> property = t.GetProperties();
20             foreach (PropertyInfo prpInfo in property)
21             {
22                string sProName= prpInfo.Name;
23                object obj= prpInfo.GetValue(info, null);
24                MessageBox.Show(sProName);
25                list.Add(obj);
26             }
27             return list;
28         } 

2.C#迭代器

3.IEnumerable接口

参考文献:

http://www.cnblogs.com/zoupeiyang/archive/2010/04/08/1707472.html

posted @ 2012-12-29 11:34  太一吾鱼水  阅读(145)  评论(0编辑  收藏  举报