Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. To access and print the values in Hashtable?

To access and print the values in Hashtable?

Scheduled Pinned Locked Moved C#
question
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MudkiSekhon
    wrote on last edited by
    #1

    How can i print the values contained in System.Collections.Hashtable............... Thanks, Sandeep +919891027854

    M 1 Reply Last reply
    0
    • M MudkiSekhon

      How can i print the values contained in System.Collections.Hashtable............... Thanks, Sandeep +919891027854

      M Offline
      M Offline
      Maqsood Ahmed
      wrote on last edited by
      #2

      foreach(object obj in hashTable.Values) { //Print obj } HTH, Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net

      M 1 Reply Last reply
      0
      • M Maqsood Ahmed

        foreach(object obj in hashTable.Values) { //Print obj } HTH, Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net

        M Offline
        M Offline
        MudkiSekhon
        wrote on last edited by
        #3

        Thanks Maqsood for ur reply. But when printing , it alos prints System.Collections.Hashtable, that is the type........... Thanks, Sandeep +919891027854

        M 1 Reply Last reply
        0
        • M MudkiSekhon

          Thanks Maqsood for ur reply. But when printing , it alos prints System.Collections.Hashtable, that is the type........... Thanks, Sandeep +919891027854

          M Offline
          M Offline
          miah alom
          wrote on last edited by
          #4

          Does it help IDictionaryEnumerator en = h.GetEnumerator(); while (en.MoveNext()) { Console.WriteLine(en.Key + " : " + en.Value); }

          M 1 Reply Last reply
          0
          • M miah alom

            Does it help IDictionaryEnumerator en = h.GetEnumerator(); while (en.MoveNext()) { Console.WriteLine(en.Key + " : " + en.Value); }

            M Offline
            M Offline
            MudkiSekhon
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • M MudkiSekhon

              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

              M Offline
              M Offline
              Maqsood Ahmed
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • M Maqsood Ahmed

                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

                M Offline
                M Offline
                MudkiSekhon
                wrote on last edited by
                #7

                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

                M 1 Reply Last reply
                0
                • M MudkiSekhon

                  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

                  M Offline
                  M Offline
                  Maqsood Ahmed
                  wrote on last edited by
                  #8

                  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

                  M 1 Reply Last reply
                  0
                  • M Maqsood Ahmed

                    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

                    M Offline
                    M Offline
                    MudkiSekhon
                    wrote on last edited by
                    #9

                    Ur 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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups