To access and print the values in Hashtable?
-
How can i print the values contained in System.Collections.Hashtable............... Thanks, Sandeep +919891027854
-
How can i print the values contained in System.Collections.Hashtable............... Thanks, Sandeep +919891027854
foreach(object obj in hashTable.Values) { //Print obj }
HTH, Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net -
foreach(object obj in hashTable.Values) { //Print obj }
HTH, Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.netThanks Maqsood for ur reply. But when printing , it alos prints System.Collections.Hashtable, that is the type........... Thanks, Sandeep +919891027854
-
Thanks Maqsood for ur reply. But when printing , it alos prints System.Collections.Hashtable, that is the type........... Thanks, Sandeep +919891027854
-
Does it help IDictionaryEnumerator en = h.GetEnumerator(); while (en.MoveNext()) { Console.WriteLine(en.Key + " : " + en.Value); }
I think there r again HashTables contained within the HashTable. That is why, it again prints System.Collections.Hashtable with output. Plz tell me the way to retrieve the values from Hashtables within Hashtables. Thanks, Sandeep +919891027854
-
I think there r again HashTables contained within the HashTable. That is why, it again prints System.Collections.Hashtable with output. Plz tell me the way to retrieve the values from Hashtables within Hashtables. Thanks, Sandeep +919891027854
Hello, You can call the same method recursively to get the values from the hashtable. Some like this:
private void PrintHashtable(Hashtable hash) { foreach(DictionaryEntry de in hash) { if(de.Value is Hashtable) { Console.WriteLine("Printing Values for Hashtable - " + de.Key); PrintHashtable((Hashtable)de.Value); } else Console.WriteLine(de.Key + " - " + de.Value); } }
Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net -
Hello, You can call the same method recursively to get the values from the hashtable. Some like this:
private void PrintHashtable(Hashtable hash) { foreach(DictionaryEntry de in hash) { if(de.Value is Hashtable) { Console.WriteLine("Printing Values for Hashtable - " + de.Key); PrintHashtable((Hashtable)de.Value); } else Console.WriteLine(de.Key + " - " + de.Value); } }
Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.netHello Maqsood, ur method to print inner Hashtables worked out very well. They printed all the key value pairs in them. Plz tell me how I can print a particular key value pair from those key value pairs. If possible send me the code. Thanks, Sandeep +919891027854
-
Hello Maqsood, ur method to print inner Hashtables worked out very well. They printed all the key value pairs in them. Plz tell me how I can print a particular key value pair from those key value pairs. If possible send me the code. Thanks, Sandeep +919891027854
if(hash.ContainsKey(theRequiredKey)) { object theValue = hash[theRequiredKey]; if(theValue is Hashtable) PrintHashtable((Hashtable)theValue); else Console.WriteLine(theValue); }
Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net -
if(hash.ContainsKey(theRequiredKey)) { object theValue = hash[theRequiredKey]; if(theValue is Hashtable) PrintHashtable((Hashtable)theValue); else Console.WriteLine(theValue); }
Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.netUr above doesn't work for me. I had tried ur earlier sent code and it worked very well. It printed the output as: Printing values for Hashtable - 2 entity.description - sandeep.co.in entity.currentstatus - Active orders.orderid - 2235000 entity.entyid - 2235000 orders.timestamp - 2005-12-07 12:02:02.011307 .................... ............. Printing values for Hashtable - 3 entity.description - sandeep.biz entity.currentstatus - Active entity.orderid - 2234999 ................... .................. Now the problem is I want to print the value of key "entity.description" for every inner Hashtable. Thanks, Sandeep +919891027854