Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

List<string> vs. string[]

0 views
Skip to first unread message

Luigi

unread,
Oct 13, 2008, 5:21:01 AM10/13/08
to
Hi all,
what are the differences (performance, features, capabilities, etc.) between
a List of string and an array of string?
I'd like to know when it's better one or another (I'm using C# 2.0)

Thanks in advance.


--
Luigi
http://blogs.dotnethell.it/ciupaz/

Marc Gravell

unread,
Oct 13, 2008, 5:48:36 AM10/13/08
to
Unless you know your data is fixed size (which is quite rare), an array
is usually very prohibitive, since there is no Add/Remove. List<T>
itself also offers many additional methods compared to T[] - however,
you might not need them all for simple data like strings.

Working within an array will be marginally quicker (not much) since the
bounds checking is simpler and there is less abstraction (a List<T>
actually wraps a T[], so it can *only* get slower). In most cases, the
difference is negligible - and consider that adding data to an array
(i.e. increasing the size by 1 each time) is very slow compared to
List<T>'s doubling approach.

Marc

Luigi

unread,
Oct 13, 2008, 6:16:03 AM10/13/08
to
"Marc Gravell" wrote:

Thanks Marc, now it's clearer.

L
>

0 new messages