Re: Array vs List<>

Daniel Barla-Szabo <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <001301c93c2c$100a5530$301eff90$@com>
Personally, I tend to have similar opinions as those in the article.  The
use of Array as opposed to List<> is not really clarifying things, since the
contents of the array can still be modified.  To be really finicky, I also
find that having to use the static Array.Sort / Array.Find methods as
opposed to the List<> counterparts a touch less clean.  I agree with this
being slightly academic; honestly, there usually are more serious issues to
deal with, unless you are writing something that is likely to be used by a
very large number of developers, in which case rolling your own immutable
list class might be worthwhile.

--Daniel.



-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[email protected]] On Behalf Of Michael
Sent: 01 November 2008 03:28 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Array vs List<>

You might find this piece from Eric Lippert worth a read:-
http://blogs.msdn.com/ericlippert/archive/2008/09/22/arrays-considered-somew
hat-harmful.aspx 

--Michael


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[email protected]] On Behalf Of Simon Robinson
Sent: 01 November 2008 13:01
To: [email protected]
Subject: [ADVANCED-DOTNET] Array vs List<>

Very minor issue that occurred to me.

The project I'm working on seems to have quite a few lists of objects, where
each list is read in from a file when the application starts, and is
subsequently guaranteed never to change; the data will be accessed
constantly but neither the list nor the values of the objects in it will
ever be modified.  

Because I don't know how many elements are going to be in the list until
I've read them in, I tend to read them into a List<>, so I can dynamically
expand it as I'm reading the elements in. However, because the list is then
unchanged, there's no reason for it to be a dynamically expandable list. If
it wasn't for the initialization process I'd just store them in a
fixed-length array.

So I'm curious, what are people's thoughts on keeping the data permanently
in a list<>, or discarding the list<> and copying to an array as soon as the
data is read in? An array entails the extra copy operation, but may lead to
slightly clearer code. I'm guessing for subsequent read access, there's no
performance difference. Any other factors I've missed?

I realise this is most likely a pretty academic point that would have very
little impact on the app either way, but I was curious...

===================================
View archives and manage your subscription(s) at
http://peach.ease.lsoft.com/archives

No virus found in this incoming message.
Checked by AVG. 
Version: 7.5.549 / Virus Database: 270.8.5/1759 - Release Date: 31/10/2008
16:10
 

No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.549 / Virus Database: 270.8.5/1759 - Release Date: 31/10/2008
16:10
 

===================================
View archives and manage your subscription(s) at
http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.