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. Hashtable vs. Dictionary (key values)

Hashtable vs. Dictionary (key values)

Scheduled Pinned Locked Moved C#
visual-studioquestion
3 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.
  • H Offline
    H Offline
    honeyman_can
    wrote on last edited by
    #1

    Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?

    D E 2 Replies Last reply
    0
    • H honeyman_can

      Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?

      D Offline
      D Offline
      Dustin Metzgar
      wrote on last edited by
      #2

      Both will throw an exception when you do an Add() with the same key. You can change the value paired with a key with the indexer though.


      Logifusion[^]

      1 Reply Last reply
      0
      • H honeyman_can

        Can a Hashtable accept two key values that are the same? if yes, then why can't a dictioanary accept two key values that are the same as it inherits from the hashtable class?

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        You have to write your own in order to have duplicates and there are a lot of valid reasons to have duplicates. A possible solution is to associate the key with a list or hash and inside the list have the objects with duplicate keys.

        A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

        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