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. Insert Duplicate into Hashset

Insert Duplicate into Hashset

Scheduled Pinned Locked Moved C#
question
6 Posts 6 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.
  • S Offline
    S Offline
    sharma ravi21
    wrote on last edited by
    #1

    Hello Every one, how can i insert duplicate value in HashSet

    L P L D M 5 Replies Last reply
    0
    • S sharma ravi21

      Hello Every one, how can i insert duplicate value in HashSet

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      You can't, by definition: The HashSet<(Of <(T>)>) class provides high performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order. :omg:

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      1 Reply Last reply
      0
      • S sharma ravi21

        Hello Every one, how can i insert duplicate value in HashSet

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        You can't. Would the negative of the value work for you? Or use a Dictionary with a count of how many of the item you have. Or a Dictionary with a List of the duplicate items.

        1 Reply Last reply
        0
        • S sharma ravi21

          Hello Every one, how can i insert duplicate value in HashSet

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you must insert duplicates, then you are using the wrong type. Use a type that allows duplicates, a List for example.

          1 Reply Last reply
          0
          • S sharma ravi21

            Hello Every one, how can i insert duplicate value in HashSet

            D Offline
            D Offline
            Dean Oliver
            wrote on last edited by
            #5

            Check this url to help decipher when to use what collection class. http://geekswithblogs.net/BlackRabbitCoder/archive/2011/06/16/c.net-fundamentals-choosing-the-right-collection-class.aspx[^]

            1 Reply Last reply
            0
            • S sharma ravi21

              Hello Every one, how can i insert duplicate value in HashSet

              M Offline
              M Offline
              Montasser Ben Ouhida
              wrote on last edited by
              #6

              Hi, You can use the HashSet as: Hashset(Key(Type1), Value (List(Type2)))

              Dictionary> dicElements;

              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