Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is rare, in reality, that you would want to use an array. Definitely use a <code>List&lt;T&gt;</code> any time you want to add/remove data, since resizing arrays is expensive. If you know the data is fixed length, and you want to micro-optimise for some <strong>very specific</strong> reason (after benchmarking), then an array may be useful.</p> <p><code>List&lt;T&gt;</code> offers a <em>lot</em> more functionality than an array (although LINQ evens it up a bit), and is almost always the right choice. Except for <code>params</code> arguments, of course. ;-p</p> <p>As a counter - <code>List&lt;T&gt;</code> is one-dimensional; where-as you have have rectangular (etc) arrays like <code>int[,]</code> or <code>string[,,]</code> - but there are other ways of modelling such data (if you need) in an object model.</p> <p>See also:</p> <ul> <li><a href="https://stackoverflow.com/questions/75976/how-when-to-abandon-the-use-of-arrays-in-c-net">How/When to abandon the use of Arrays in c#.net?</a></li> <li><a href="https://stackoverflow.com/questions/392397/arrays-whats-the-point">Arrays, What's the point?</a></li> </ul> <p>That said, I make a <strong>lot</strong> of use of arrays in my <a href="https://github.com/mgravell/protobuf-net" rel="noreferrer">protobuf-net</a> project; entirely for performance:</p> <ul> <li>it does a lot of bit-shifting, so a <code>byte[]</code> is pretty much essential for encoding;</li> <li>I use a local rolling <code>byte[]</code> buffer which I fill before sending down to the underlying stream (and v.v.); quicker than <code>BufferedStream</code> etc;</li> <li>it internally uses an array-based model of objects (<code>Foo[]</code> rather than <code>List&lt;Foo&gt;</code>), since the size is fixed once built, and needs to be very fast.</li> </ul> <p>But this is definitely an exception; for general line-of-business processing, a <code>List&lt;T&gt;</code> wins every time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload