microkarl Posted May 1, 2008 Posted May 1, 2008 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 Quote Donald DUCK : YOU ARE FIRED!!!
MrPaul Posted May 1, 2008 Posted May 1, 2008 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: Quote Never trouble another for what you can do for yourself.
Leaders snarfblam Posted May 1, 2008 Leaders Posted May 1, 2008 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? Quote [sIGPIC]e[/sIGPIC]
mskeel Posted May 2, 2008 Posted May 2, 2008 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>(); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.