遍历类实例的成员 [英] iterating through the member of class instance

查看:65
本文介绍了遍历类实例的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends,
我有一个班级说,

Hi Friends,
I have a class say,

class a
{
public int  b;
public int  c;
...
...
public int d;
}


我想遍历成员并将值存储在b,c ... d
可能吗.你能建议一个很好的方法吗?
最好的问候


I want to iterate through the members and store values in b , c ... d
Is it possible. Can you suggest a good way of doing this.
Best Regards

推荐答案

尝试反思...

Try reflection...

typeof(a).GetProperties()



其余的只是MSDN ...



The rest is just MSDN...


似乎您要访问类型的字段并为其设置值.请看看,

FieldInfo [ FieldInfo.SetValue [
It looks like you want to access Fields of a type and set value to it. Please have a look into,

FieldInfo[^]
FieldInfo.SetValue[^]

Hope it helps :)


这篇关于遍历类实例的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆