本文共 1049 字,大约阅读时间需要 3 分钟。
1.C#获取object对象属性值
1 private void button3_Click(object sender, EventArgs e) 2 { 3 xlsCell cel=new xlsCell(1,100); 4 List 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 GetPropertyValue(object info)14 {15 List list = new List();16 if (info == null) return null;17 Type t = info.GetType();18 //IEnumerable property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;19 IEnumerable 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://dpdta.baihongyu.com/