Re: Array vs List<>

Richard Blewett <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <014301c93c4c$f4f70420$dee50c60$@com>
Well we were talking about expressing intention rather than trying to
prevent someone maliciously trying to manipulate the code - if you wrap in
ReadOnlyCollection they could of course cast to ReadOnlyCollection and then
use reflection to mutate the list. Granted about the indexer access though

Rich

> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Sébastien Lorion
> Sent: 01 November 2008 17:44
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Array vs List<>
> 
> If you dont wrap it with a read-only container, someone could cast it
> to
> IList<T> and modify the elements. Also, it's nice to have indexable
> content
> when possible.
> 
> Sébastien
> On Sat, Nov 1, 2008 at 12:11 PM, Richard Blewett
> <[email protected]>wrote:
> 
> > 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
> >
> 
> ===================================
> 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.