Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Donald DUCK : YOU ARE FIRED!!!
Posted

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:

mainHashTable.Add(x, y);

Which sub-Hashtable does that affect?

 

Good luck :cool:

Never trouble another for what you can do for yourself.
  • Leaders
Posted

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?

[sIGPIC]e[/sIGPIC]
Posted

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>();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...