A Question about Hashtable

microkarl

Regular
Joined
Apr 22, 2004
Messages
88
Location
Morristown, NJ
Is it possible to have one main Hashtable to store mulitple sub-hashtables? So it works like this:
1: Sub-Hashtable1 contains n objects (strings).
2: Sub-Hashtable2 contains n objects (strings).
3: Main-Hashtable contains these two Sub-Hashtables.
4: Retrieve these objects through the Main-Hashtable?

I have been looking into Hashtable.Values property but running into dead-end, would this achieve it?

Thanks in advance,
Carl
 
Not if you have to use Hashtable

Using the Hashtable type directly?
No.

Creating your own class which implements IDictionary<object,object> (or some more specific type)?
Yes, by having the sub-Hashtables as class variables.

You will need to consider what should happen if this occurred:
Code:
mainHashTable.Add(x, y);
Which sub-Hashtable does that affect?

Good luck :cool:
 
Re: Not if you have to use Hashtable

What are you trying to do, exactly? Do you simply want to be able to grab objects by hash code without manually checking multiple tables?
 
Perhaps a class with hashtables as members might work?

Code:
class SomeClass
{
public hashtable sub1 = new Hashtable(); //you might want to use generics here instead of hashtables
public hashtable sub2 = new Hashtable();
public hashtable sub3 = new Hashtable();
// Except this would be done using better OO techniques
}


Then you would use the Dictionary generic as suggested by MrPaul:

Code:
Dictionary<string, SomeClass> data = new Dictionary<string, SomeClass>();
 
Back
Top