views:

51

answers:

2

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 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?

+2  A: 

I would define it as an array, I think the IEnumerable is serialized as an array anyway.

Stefan Steinegger
+4  A: 

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.

Christian Hayter