473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2580
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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP09.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
11109
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 i load the dll everything is fine and when i load then the objects into an Hashtable or Arraylist of the main program it freezes 5MB each which i don't get free. The weird think is, when i reload the Tables a second time on a new local variable...
6
21477
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 'column' in the ArrayList, the other is automatically sorted and so I can use IndexOf without fear. This is because I will be going through 20,000 some odd records and don't want to use a Lookup type of table/query; I figure an ArrayList.IndexOf method...
5
12486
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 Hashtable hash = arraylist
5
65348
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
33550
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 example, if the ArrayList has the following elements: elems = "blue" elems = "red" elems = "blue" elems = "green"
3
9695
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 atemp = new ArrayList(); // THE ARRAY StreamWriter sw = new StreamWriter(@"C:\temp\fred.html");
10
8514
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 Hashtable()); 2. create ArrayList aList = ArrayList.Synchronized(new ArrayList()); 3. create a string sList = ""; For 1 and 2, since the list is synced, many threads can directly
8
2596
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; m_ResultArray.Add ( aFoundObject);
7
2679
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 foreach loop I retreive the corresponding hashtable from the masterArrayList and add new strings to existing_strings after comparing the hashtable keys. The problem is that when I add a new value to an existing_strings arraylist it also add the new...
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.