Re: Array vs List<>

Richard Blewett <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
Why not just expose it as an IEnumerable<T> that saves the copy and  
keeps the list ( but not it's members) immutable

Rich

Sent from my iPhone

On 1 Nov 2008, at 13:00, Simon Robinson <[email protected]> wrote:

> 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

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