473,326 Members | 2,108 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,326 software developers and data experts.

ArrayList versus HashTable

I've been reading up on Arrays in ASP.NET. I'm going to create an two
dimensional array of some type to contain 5 columns but a variable amount of
rows. I read up on the ArrayList function and the HashTable as well. In
the two books I have, there's no mention of the limitations of an ArrayList
and it can only contain a single column array. But from the examples, I've
seen, this seems to be true. The HashTable, as far as I can tell, can
contain key/pairs but can it contain 5 columns of data?

So considering my needs, would you suggest an old fashioned Array or try one
of the others mentioned above and why?

(I'm still working towards my "yellow belt" in .NET so I'm still pretty
new.)

Thanks in advance!
Nov 18 '05 #1
2 2554
In both a Hashtable (or Dictionary) and an Arraylist, you could store an
object as the value. The object could be a DataRow with 5 columns, or your
own object with 5 variables in it. The difference would be if you would like
to be able to find the correct entry by using a key in the key-value pair.
You could use some primary identifier as the key for each entry in the
hashtable to quickly find the entry with the correct 5 columns you are
looking for. With an Arraylist you would have to find the entry by matching
the exact object, or looping through them. Arraylists are real easy to use,
though, if you do not need the key for finding items.

I'm sure there are many more variables to make your decision on, but that's
what I look at mostly.

-Darrin
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
I've been reading up on Arrays in ASP.NET. I'm going to create an two
dimensional array of some type to contain 5 columns but a variable amount of rows. I read up on the ArrayList function and the HashTable as well. In
the two books I have, there's no mention of the limitations of an ArrayList and it can only contain a single column array. But from the examples, I've seen, this seems to be true. The HashTable, as far as I can tell, can
contain key/pairs but can it contain 5 columns of data?

So considering my needs, would you suggest an old fashioned Array or try one of the others mentioned above and why?

(I'm still working towards my "yellow belt" in .NET so I'm still pretty
new.)

Thanks in advance!

Nov 18 '05 #2
I'm not sure where you're getting you information from, but columns have
nothing to do with either ArrayList or HashTable, or any other Collection
Type. A Collection is similar to an Array, with some added functionality,
depending upon the Collection Type. The Types ArrayList and HashTable are
Collections of type "Object" which means that they can contain any type of
object, and you can even put different types of objects into the same
Collection. Of course, using the Object type means Late Binding and poor
performance. Using Custom Typed Collections is recommended when using
Collections.

Collections are reference types while Arrays are value types, which means
that there is more processing and memory overhead in using Collections
instead of Arrays. However, if the additional functionality is desired, they
come in quite handy. In addition, Collections are not limited in length as
are Arrays (you can change the size of an Array, but it is costly, requiring
the creation of a new Array to hold the longer length).

You could use either Collections or Arrays in your case, but if you are
working with multiple "columns" of data, and the number is the same for each
element in the Collection/Array, you may find a multi-dimensional Array more
useful to you, as you would have to create an aggregate object to hold
multiple elements ("colum,ns") in a single Collection Item, such as structs
or arrays or classes. Another alternative would be to use a DataTable, which
you can build dynamically, adding colums and rows as needed.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
I've been reading up on Arrays in ASP.NET. I'm going to create an two
dimensional array of some type to contain 5 columns but a variable amount of rows. I read up on the ArrayList function and the HashTable as well. In
the two books I have, there's no mention of the limitations of an ArrayList and it can only contain a single column array. But from the examples, I've seen, this seems to be true. The HashTable, as far as I can tell, can
contain key/pairs but can it contain 5 columns of data?

So considering my needs, would you suggest an old fashioned Array or try one of the others mentioned above and why?

(I'm still working towards my "yellow belt" in .NET so I'm still pretty
new.)

Thanks in advance!

Nov 18 '05 #3

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

Similar topics

7
by: Matthias Kwiedor | last post by:
Hi@all! I have a app (c#) where i load up a external dll (managed code from c#) with a small arraylist and hashtable in two routines (about 40000 objects in each arraylist and hashtable). If...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
5
by: Matthias Kwiedor | last post by:
Hi! What i want to do, is to put an ArrayList into a Hashtable. So i can access the ArrayList fast over the key-indexing of the Hashtable. What i did is to put the ArrayList into the...
5
by: Netmonster | last post by:
Hello, Does any one have an example of how to create an ArrayList of objects? i.e. ArrayList of ArrayLists or an ArrayList of Hashtables? Thanks in advance KC
11
by: paradox | last post by:
Basically I have an ArrayList of strings; I need a fast way of searching through and comparing the elements of the ArrayList and the return an ArrayList of items that have 3 Duplicates. For...
3
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
7
by: Kamran Shafi | last post by:
Hi, I am creating an arraylist (say masterArrayList) of hashtables, where each hashtable (say table) is of the format key=string, value = arraylist of strings (say existing_strings). In a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.