473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Array versus Collections

What is the major differences between array and collection? For example,
ArrayList. When to use which? I think array is static container, but
collection is dynamic container. The drawback of array is to define the size
in declaration, but not in collection.

Please advise...


Nov 15 '05 #1
1 12552
Matt,

I'll assume you have NOT read the MSDN documentation on Array, ArrayList and
a Collection. Which you should!

As for when to use which, it is more of a style or speed issue.

Something to keep in mind is that a collection is nothing more than array
that has a whole lot of code wrapped around it to manage adding/expanding
the array. This is why speed can be an issue.

Now since most applications need to be more maintainable than fast, I try to
use the following guide lines when deciding which to use.
If you know the number of objects to be stored use an array. If not, use a
collection.
If after creating an array a process must add an unknown number of objects
to it use a collection.

In my experiance designing reusable objects, It is not a good practice to
allow objects to return/expose Arrays or ArrayLists. This is because it
never fails that I have to end up and add code to all my methods to make
sure that each list object is the type that I'm expecting. What I do is to
create a class that inherats from CollectionBase so that only objects of
expected types are allowed to be added. By doing this it forces a "Strong
Typed" structure, which is the been found to be the easiest to
code(opinion).

Hope this helps.
--
Glen Jones MCSD
"Matt" <ma*******@hotmail.com> wrote in message
What is the major differences between array and collection? For example,
ArrayList. When to use which? I think array is static container, but
collection is dynamic container. The drawback of array is to define the size in declaration, but not in collection.

Please advise...

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Kurzweil | last post by:
I need to make a two dimensional array of objects. These objects are of type Influence. How do I declare such an array? Now I use: private object influences; influences = GetInfluences(); //...
7
by: Marc Bishop | last post by:
Hi can anyone help? I'm making a shopping cart and am stuck on removing an item from my array? The array is made : cArray(ITEM_NAME,cItem) = ProductName
1
by: Pi | last post by:
I'm looking at a piece of code that gets called over 100,000 times and was wondering if there would be much performance difference between these three scenarios or is there an alternate approach?:...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
11
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.