Gauls Posted July 7, 2006 Share Posted July 7, 2006 Hi i have two hashtablesexample :Hashtable 1 Hashtable 2key Value key ValueDetails Order Details ProductCan i get One Order from 1st hashtable and then One product from the second hashtable ?Thanks Link to comment Share on other sites More sharing options...
aspnetguy Posted July 7, 2006 Share Posted July 7, 2006 I don't understand what you are trying to do. Can you explain a little more. Link to comment Share on other sites More sharing options...
pulpfiction Posted July 7, 2006 Share Posted July 7, 2006 I am not sure if I understood the question correctly, To get the value from the hashtables....Dim key = "2" 'some numberResponse.Write(hashtable1(key))Response.Write(hashtable2(key)) Link to comment Share on other sites More sharing options...
Gauls Posted July 7, 2006 Author Share Posted July 7, 2006 I am not sure if I understood the question correctly, To get the value from the hashtables....Dim key = "2" 'some numberResponse.Write(hashtable1(key))Response.Write(hashtable2(key))<{POST_SNAPBACK}> My Question is Incase if i have two hashTables and does not contain same key values , so there is no link between the two tables right. Now i want to loop thru both the hashtables at a time like one value from 1st hashtable and one value from the 2nd hashtable then move next ....so on Can i use for i as integer=0 to ht.count or something like that ?? Link to comment Share on other sites More sharing options...
pulpfiction Posted July 7, 2006 Share Posted July 7, 2006 This will give the number of keys in the tableDim cnt As Integer = hashtable.Keys.Count() Link to comment Share on other sites More sharing options...
Gauls Posted July 7, 2006 Author Share Posted July 7, 2006 This will give the number of keys in the tableDim cnt As Integer = hashtable.Keys.Count()<{POST_SNAPBACK}> sorry but that doesn't help as i am unable to retieve any value from the hashtable without the keys Link to comment Share on other sites More sharing options...
pulpfiction Posted July 7, 2006 Share Posted July 7, 2006 Try this code, this will give you the complete list of keys and its corresponding values...Dim myEnumerator As IDictionaryEnumerator = hashtablename.GetEnumerator()While myEnumerator.MoveNext()Response.Write("<BR>" + myEnumerator.Key.ToString() + ", " + myEnumerator.Value.ToString())End While Link to comment Share on other sites More sharing options...
aspnetguy Posted July 7, 2006 Share Posted July 7, 2006 you can do it 2 ways Hashtable ht = new Hashtable();ht.Add("one","1");ht.Add("two","2");ht.Add("three","3");string[] vals = new string[ht.Count];ht.Values.CopyTo(vals,0);for(int i=0;i<keys.Length;i++){ Response.Write(vals[i].ToString());} Hashtable ht = new Hashtable();ht.Add("one","1");ht.Add("two","2");ht.Add("three","3");string[] keys = new string[ht.Count];ht.Keys.CopyTo(keys,0);for(int i=0;i<keys.Length;i++){ Response.Write(ht[keys[i]].ToString());} For whatever reason when the Hashtable is copied it is copied backwards. You will see what I mean when you run the code.You can fix that by running hte for loop like this for(i=keys.Length-1;i>=0;i--){ //i didn't test this part so it might be off a bit} EDIT: oops I didn't see pulpfictions post. His solution looks cleaner. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now