在排序的dotnet反思的请求dotnet

2023-09-05 02:17:04 作者:对xx脸红.

当我打电话的GetProperties,()的一个类型,属性是有序的,因为它们都写在源$ C ​​$ C。这是非常方便的,但我的问题是,如果这是一个保证的行为,也可能这种变化取决于运行时版本和环境。有谁知道一些事?

When I call GetProperties() on a type, the properties are ordered as they are written in the source code. This is very handy but my question is, if this is a guaranteed behavior or may this change depending on the runtime version and the environment. Does anyone know something about that?

推荐答案

没有,你不能假设的顺序将保持不变。

No, you can't assume the order will stay the same.

从 DOC 报价:

的getProperties方法不返回一个特定的顺序性,如按字母顺序或声明顺序。您的code一定不能依赖于它的属性返回的顺序,因为该顺序有所不同。的