如何循环类的字段名称?
我有一个包含超过 160 个字段的类。我需要数组中的字段名称(而不是值)。 我需要帮助来循环遍历字段名称或获取数组中的字段名称列表,以便我可以循环它并在代码中使用它。我正在使用视觉工作室 2010
I have got a class which contains more then 160 fields. i need the name of fields (not value) in an array.
i need help to get loop through names for field or get list of field names in a array so that i can loop over it and use it in code. i am using visual studio 2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个例子
http://www.dotnetperls.com/reflection-field
Try this example from
http://www.dotnetperls.com/reflection-field
您可以使用反射来获取所有字段,
然后您可以使用
FieldInfo
的Name
属性来获取字段的名称You can use reflection to get all the fields
then you can use
Name
property ofFieldInfo
to get name of your field