您的位置:首页 > 编程语言 > C#

C#迭代器

2012-12-29 11:34 393 查看
1.C#获取object对象属性值

object对象属性值获取

private void button3_Click(object sender, EventArgs e)
{
xlsCell cel=new xlsCell(1,100);
List<object> lis=GetPropertyValue(cel);
string s=string.Empty;
foreach (object o in lis)
{
s += string.Format("_{0}", o.ToString());
}
MessageBox.Show(s);
}

public static List<object> GetPropertyValue(object info)
{
List<object> list = new List<object>();
if (info == null) return null;
Type t = info.GetType();
//IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
IEnumerable<System.Reflection.PropertyInfo> property = t.GetProperties();
foreach (PropertyInfo prpInfo in property)
{
string sProName= prpInfo.Name;
object obj= prpInfo.GetValue(info, null);
MessageBox.Show(sProName);
list.Add(obj);
}
return list;
}


2.C#迭代器

3.IEnumerable接口

参考文献:

/article/6104827.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: