What is the difference between:
int[] myIntArray
and
list<int> myIntArray
?
In web services I read that I should pick one or the other and not mix the two, why?
On the wire they will be indistinguishable - i.e. both Customer[]
and List<Customer>
are going to look (roughly) like:
<Customers>
<Customer name="Fred" ... />
<Customer name="Barney" ... />
</Customers>
So there is no point having logic that treats the two differently. Ultimately, int[]
is a pain to work with (Add
etc), so I would tend to use List<T>
- of course, wsdl.exe
nicely defaults to arrays, IIRC - but there is a command line switch (or perhaps there is for wse/wcf).
Depends on what you will be doing with them.
If your dataset is of a fixed size and you will not need to do any sorting, the array is better suited.
If your data needs to be more dynamic, allow for sorting, and be able to take advantage of LINQ, then use the list
Personally, I prefer the flexibility of list types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With