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?
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.
int[] is an array of integers. List is a generic list that holds objects of type int
Which one you pick depends on your requirements. If you are dealing with immutable collections of objects, int[] would be more suitable. However, if you need to modify the contents of the collection, List provides that flexibility.
They are functionally equivalent, so you can use either one. Once you use one version, be consistent. It'll help keep your code readable and easier to maintain.
They are pretty much the same, except that Lists have a lot of built in functions to ease the life of the programmer. Once you start using lists, you'll love them :D
Also, arrays are fixed. You cannnot (easily) change the size of an array.