tags:

views:

50

answers:

1

Does Type.GetProperties() guarantee a certain order for its PropertyInfo[] result? Such as returning them in alphabetical order by property name or the order they appear in code. Or is the order undefined?

+4  A: 

From MSDN:

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.

Martin Harris
Doh! I must have skimmed over that part. Note to self: wait a day before posting my stupid question. :)
Jonathon Watney
It does seem to be consistent though. I have a test application that uses GetProperties to define and populate a DataGridView and the types and values the separate calls return always match.
ChrisF
@ChrisF: Are they in some arbitrary order or is there a pattern? If anything I thought they would be in the order they appeared in the code.
Jonathon Watney
+1 for the Doh! factor. I've done that many times myself. :)
Mike Hofer
I would think that the order depends on the order they appear in the assembly; however, since the order they appear in the assembly can change from one build to another (depending on changes to the code), MSDN is telling you (sagely) don't count on a fixed order.
Mike Hofer