System.Reflection.PropertyInfo 数组

发布于 2024-09-16 12:17:19 字数 107 浏览 1 评论 0原文

获取类的 System.Reflection.PropertInfo 数组后 - 有谁知道这个数组如何排序或是否排序,或者我是否必须 Array.Sort(MySortMethods/Params)?

After Getting a System.Reflection.PropertInfo array for a class- Does anyone know how or if this array is sorted or do I have to Array.Sort(MySortMethods/Params)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

葬心 2024-09-23 12:17:19

大概您正在通过调用 < 来获取 PropertyInfo 数组code>GetProperties,在这种情况下,无法保证数组的顺序。

来自 MSDN 文档

GetProperties 方法不
返回特定的属性
顺序,例如按字母顺序或
申报单。你的代码一定不能
取决于其中的顺序
返回属性,因为
顺序各不相同。

Presumably you're getiing the PropertyInfo array by calling GetProperties, in which case the ordering of the array isn't guaranteed.

From the MSDN documentation:

The GetProperties method does not
return properties in a particular
order, such as alphabetical or
declaration order. Your code must not
depend on the order in which
properties are returned, because that
order varies.

烟雨扶苏 2024-09-23 12:17:19

我会检查您用于获取 PropertyInfos 的方法的文档。如果它没有说明任何有关结果排序的信息,我会假设它们没有排序,并按照您的建议自行排序。

I would check the documentation for the method you're using to get the PropertyInfos. If it doesn't state anything about the ordering of results I would assume they are not ordered and order them myself as you suggest.

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