Re: Array vs List<>
Shane Courtrille <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <[email protected]> |
If you Yield return I don't think this is possible is it? On Sat, Nov 1, 2008 at 11:44 AM, Sébastien Lorion < [email protected]> wrote: > 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