如何循环类的字段名称?

发布于 2024-12-26 00:34:49 字数 105 浏览 2 评论 0原文

我有一个包含超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱她像谁 2025-01-02 00:34:49

您可以使用反射来获取所有字段,

Type type = typeof(YourType); 
FieldInfo[] fields = type.GetFields(); 

然后您可以使用 FieldInfoName 属性来获取字段的名称

You can use reflection to get all the fields

Type type = typeof(YourType); 
FieldInfo[] fields = type.GetFields(); 

then you can use Name property of FieldInfo to get name of your field

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文