|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
list of objects vs Array of objectsHi
Can anyony please tell me why I should use a List of objects instead of an array of objects ? Thanx John John Devlon wrote:
> Hi Well, John when it comes right down to it - an array is a list. I> > Can anyony please tell me why I should use a List of objects instead of an > array of objects ? > > Thanx > > John suspect you mean an array with it's fixed size vs a more dynamic list such as System.Collections.ArrayList. Well, the only reason to use one over the other has to do with the fixed size part :) If you know exactly how many objects you want to store in you list, and you know that is all your ever going to store - then by all means use an array. If you don't know how many you will have, then an arraylist is probably a better choice. That's not to say that you can't support dynamic array implementations with an array. You most certainly can - you just have to use an efficient resize & copy algorithm (well you don't have to, but your users will hate you if you don't :) . Or you can just use an ArrayList, which already does this for you :) Anyway, HTH. -- Tom Shelton Tom,
I would not have written this in your message. >That's not to say that you can't support The question was not "what is better" but "why"> dynamic array implementations with an array. You most certainly can - > you just have to use an efficient resize & copy algorithm (well you > don't have to, but your users will hate you if you don't :) . Or you > can just use an ArrayList, which already does this for you :) For the rest I would have written than of course in my words the same as you did. Cor Show quoteHide quote "Tom Shelton" <t**@mtogden.com> schreef in bericht news:1157323209.481618.45600@m79g2000cwm.googlegroups.com... > > John Devlon wrote: >> Hi >> >> Can anyony please tell me why I should use a List of objects instead of >> an >> array of objects ? >> >> Thanx >> >> John > > Well, John when it comes right down to it - an array is a list. I > suspect you mean an array with it's fixed size vs a more dynamic list > such as System.Collections.ArrayList. Well, the only reason to use one > over the other has to do with the fixed size part :) > > If you know exactly how many objects you want to store in you list, and > you know that is all your ever going to store - then by all means use > an array. If you don't know how many you will have, then an arraylist > is probably a better choice. That's not to say that you can't support > dynamic array implementations with an array. You most certainly can - > you just have to use an efficient resize & copy algorithm (well you > don't have to, but your users will hate you if you don't :) . Or you > can just use an ArrayList, which already does this for you :) > > Anyway, HTH. > > -- > Tom Shelton > Tom Shelton wrote:
Show quoteHide quote > John Devlon wrote: Ok, thinking more about this there is one more consideration if you are> > Hi > > > > Can anyony please tell me why I should use a List of objects instead of an > > array of objects ? > > > > Thanx > > > > John > > Well, John when it comes right down to it - an array is a list. I > suspect you mean an array with it's fixed size vs a more dynamic list > such as System.Collections.ArrayList. Well, the only reason to use one > over the other has to do with the fixed size part :) using VB.NET 2002 OR 2003... The type of object that you are storing in the list can be a factor as well. If the list is potentially large, and you are storing value types, then you would probably be better off with implementing a custom collection wrapped around a dynamic array implementation. The reason is that when you use the standard ArrayList your dealing with values of type object, and so incure boxing penalties when working with the values stored in the list. Of course, this isn't an issue with VB.NET 2005 if you use the generic list implementation (System.Collections.Generic.List). -- Tom Shelton
Diff between 'n-tier' vs 'distributed architecture' vs. 'multi-layered programming'?
Please, can anyone convert the following dot net snippet to pascal VB .NET FTP Read Javascript Messagebox content from webclient Loop Question get create table script for a SQL Server object sound capture (record audio input) in VB.NET???? Why this warning in IDE? VB2005 EXPRESS Photoshop from vb |
|||||||||||||||||||||||