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. How To Iterate the Hashtable in C#

How To Iterate the Hashtable in C#

Scheduled Pinned Locked Moved C#
csharpphpcomdockerhelp
4 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.
  • E Offline
    E Offline
    elizas
    wrote on last edited by
    #1

    If we write in the same way as above for the hashtable then we would not get the desired values. Hashtable ss = new Hashtable(); ss["key1"] ="india"; ss["key2"] = "bharat"; foreach (object gg in ss) { Console.WriteLine("Key value is " + gg); Console.Read(); } Here we get System.Collections.DictionaryEntry and System.Collections.DictionaryEntry as output instead of the value pairs stored in the hashtable. In this case we can help of DictinaryEntry object for iterating the hashtable. foreach(DictionaryEntry gg in ss) { Console.WriteLine("Key and value are " + gg.Key + " " + gg.Value); Console.Read(); } A DictionaryEntry object is simply a container containing the Key and Value . http://www.mindfiresolutions.com/How-To-Iterate-the-Hashtable-in-C-311.php[^]

    Cheers, Eliza

    A 1 Reply Last reply
    0
    • E elizas

      If we write in the same way as above for the hashtable then we would not get the desired values. Hashtable ss = new Hashtable(); ss["key1"] ="india"; ss["key2"] = "bharat"; foreach (object gg in ss) { Console.WriteLine("Key value is " + gg); Console.Read(); } Here we get System.Collections.DictionaryEntry and System.Collections.DictionaryEntry as output instead of the value pairs stored in the hashtable. In this case we can help of DictinaryEntry object for iterating the hashtable. foreach(DictionaryEntry gg in ss) { Console.WriteLine("Key and value are " + gg.Key + " " + gg.Value); Console.Read(); } A DictionaryEntry object is simply a container containing the Key and Value . http://www.mindfiresolutions.com/How-To-Iterate-the-Hashtable-in-C-311.php[^]

      Cheers, Eliza

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      Did you post this in the wrong place? Perhaps you meant to post a tip/trick? Or maybe you meant to post this at the bottom of an article? This is a forum for C# questions.

      [Forum Guidelines]

      OriginalGriffO 1 Reply Last reply
      0
      • A AspDotNetDev

        Did you post this in the wrong place? Perhaps you meant to post a tip/trick? Or maybe you meant to post this at the bottom of an article? This is a forum for C# questions.

        [Forum Guidelines]

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Nah, I think he just missed and gave us his lecture notes instead of his homework question... :laugh:

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        A 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Nah, I think he just missed and gave us his lecture notes instead of his homework question... :laugh:

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          The link points to the same thing posted by the OP. I am honestlly baffled. :doh:

          [Forum Guidelines]

          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