Can I guarantee insertion order of IEnumerables over WCF?
If I have a WCF service which accepts an IEnumerable as a parameter to a function, is the order that I look up the elements guaranteed开发者_JS百科 to be the same as they were added to the collection? (Or at least the same order they were sent across the wire?)
If not, is there a way that I can guarantee the order, such as defining it in the service contract as a List?
The serialiser will naturally serialise items in the order in which they are served up by the collection's enumerator. For a List
or Array
, this will always be the order in which they are added, but for anything based on a hashtable, the order is not guaranteed. To guarantee the order, use an array-based collection.
I would define it as an array, I think the IEnumerable is serialized as an array anyway.
精彩评论