473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList in Hashtable

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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias
Nov 16 '05 #1
5 12486
Matthias,

The only way that this could happen (assuming that hash is the same
hashtable in both instances) is if the key that was used to fetch the
ArrayList is different than the key that was used to get the ArrayList. Are
you sure they are the same?

Also, are you sure that nothing modified hash or the value pointed to by
key between the time that you set it and the time you try to access it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Matthias Kwiedor" <cr********@hot mail.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #2
Matthias,

The only way that this could happen (assuming that hash is the same
hashtable in both instances) is if the key that was used to fetch the
ArrayList is different than the key that was used to get the ArrayList. Are
you sure they are the same?

Also, are you sure that nothing modified hash or the value pointed to by
key between the time that you set it and the time you try to access it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Matthias Kwiedor" <cr********@hot mail.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #3
Matthias Kwiedor <cr********@hot mail.com> wrote:
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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.


Did you ever actually initialise arraylist to have a reference to an
actual instance of ArrayList, rather than just being null?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Matthias Kwiedor <cr********@hot mail.com> wrote:
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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.


Did you ever actually initialise arraylist to have a reference to an
actual instance of ArrayList, rather than just being null?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
This can happen if the object which is your key overides Equals() and
returns false erroneously.

Try this:

bool valid = hash.ContainsKe y(key);

What is "valid" - if its false - then it's not finding a match to your key.

"Matthias Kwiedor" <cr********@hot mail.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
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[key] = arraylist
When i get the ArrayList back

ArrayList array = (ArrayList)hash[key]

But when i try to access array (for example array.Count) i get a null
reference exception.

Can someone help me out of there.

Regars

Matthias

Nov 16 '05 #6

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
21478
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
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
33554
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");
3
2300
by: Sam | last post by:
Hi Everyone, I have a stucture below stored in an arraylist and I want to check user's input (point x,y) to make sure there is no duplicate point x,y entered (string label can be duplicated). Is there a way to compare the new input point x,y without having to a loop and compare the whole object in the array list. I can't use the indexof method because it would compare the whole object. Public Structure
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
2
2467
by: Bruce | last post by:
Hi I am having a problem understanding the exact advantages of using an ArrayList over a Hashtable in any situation. In most areas of an application I am working on, lookup needs to be fast. If I use a hashtable Addition - O(1) - same as ArrayList Removal - O(1) - same as ArrayList Lookup- O(1) - ArrayList is O(n) Memory - Maybe slightly more than ArrayList since we have a hash to store.
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
9655
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
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9964
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...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
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
3
2894
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.