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. What's the best collection

What's the best collection

Scheduled Pinned Locked Moved C#
databasehelpquestion
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.
  • C Offline
    C Offline
    CodingLover
    wrote on last edited by
    #1

    Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

    I appreciate your help all the time... CodingLover :)

    C D K R M 5 Replies Last reply
    0
    • C CodingLover

      Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

      I appreciate your help all the time... CodingLover :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      There is no set class in .NET. You'd have to add set behaviour to a list, by searching for items and not inserting them if they exist.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      1 Reply Last reply
      0
      • C CodingLover

        Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

        I appreciate your help all the time... CodingLover :)

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        AFAIK there isn't one. You can always create your own and use new a new Add method - something like

        public class MyList<T> : List<T>
        {
        public new void Add(T item)
        {
        if (!Contains(item))
        base.Add(item);
        }
        }

        You'll need to do something similar for AddRange, and keep track of any changing items to make sure they don't create duplicates.

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        1 Reply Last reply
        0
        • C CodingLover

          Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

          I appreciate your help all the time... CodingLover :)

          K Offline
          K Offline
          kb boxer
          wrote on last edited by
          #4

          There is library available from Wintellect that has unordered set, the one you are looking for. You might try it if you wish.

          http://vivekragunathan.spaces.live.com

          Programming is an art. Code is a poem

          1 Reply Last reply
          0
          • C CodingLover

            Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

            I appreciate your help all the time... CodingLover :)

            R Offline
            R Offline
            Rob Philpott
            wrote on last edited by
            #5

            It's worth remembering that there isn't a one-size-fits all algorithm to do stuff like this. The framework provides a set of general purpose collections and algorithms, but they might not be good enough in specific scenarios. An unsorted list, which is what I understand you want, is going to be very slow at detecting duplicates. And its going to seriously degrade if you've got lots and lots of things in your collection. It might be worth running two data structures alongside each other to mitigate this. So, roughly how many things are you going to insert into this? Is memory consumption an issue for you? Can we remove duplicates later on, or does it have to be done on insertion?

            Regards, Rob Philpott.

            1 Reply Last reply
            0
            • C CodingLover

              Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)

              I appreciate your help all the time... CodingLover :)

              M Offline
              M Offline
              Mirko1980
              wrote on last edited by
              #6

              If you can use .NET 3.5, there is an HashSet class. Otherwise, you have to build one, as others have said.

              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