Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between int[] and list<int>

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?

like image 885
Bryan Avatar asked Dec 14 '22 01:12

Bryan


2 Answers

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).

like image 158
Marc Gravell Avatar answered Dec 22 '22 00:12

Marc Gravell


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.

like image 28
Chris Ballance Avatar answered Dec 22 '22 01:12

Chris Ballance