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. Is there a collection in .NET that combines the functionality of both a List and a Dictionary?

Is there a collection in .NET that combines the functionality of both a List and a Dictionary?

Scheduled Pinned Locked Moved C#
csharpcomquestion
6 Posts 4 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.
  • W Offline
    W Offline
    Waleed Eissa
    wrote on last edited by
    #1

    Hi gurus, I'm looking for a collection that combines the functionality of a list and dictionary. I basically want to be able to keep the order in which the items are added and at the same time do fast lookup? O(log n) as opposed to O(n), does this thing exist or do I have to write it myself? Regards

    Waleed Eissa Software Developer Sydney

    G F W 3 Replies Last reply
    0
    • W Waleed Eissa

      Hi gurus, I'm looking for a collection that combines the functionality of a list and dictionary. I basically want to be able to keep the order in which the items are added and at the same time do fast lookup? O(log n) as opposed to O(n), does this thing exist or do I have to write it myself? Regards

      Waleed Eissa Software Developer Sydney

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      If you can use a SortedDictionary, it's loopup is a O(log n) operation. Otherwise you need to write it yourself. Just wrap a List and a Dictionary in a class, write an Add method that adds an item to both collections, and properties to get the values by index and by key.

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      • W Waleed Eissa

        Hi gurus, I'm looking for a collection that combines the functionality of a list and dictionary. I basically want to be able to keep the order in which the items are added and at the same time do fast lookup? O(log n) as opposed to O(n), does this thing exist or do I have to write it myself? Regards

        Waleed Eissa Software Developer Sydney

        F Offline
        F Offline
        Frank Horn
        wrote on last edited by
        #3

        Guess you have to write it yourself, like KeyList with members List and Dictionary to which you delegate. But then I'm not a guru...

        1 Reply Last reply
        0
        • W Waleed Eissa

          Hi gurus, I'm looking for a collection that combines the functionality of a list and dictionary. I basically want to be able to keep the order in which the items are added and at the same time do fast lookup? O(log n) as opposed to O(n), does this thing exist or do I have to write it myself? Regards

          Waleed Eissa Software Developer Sydney

          W Offline
          W Offline
          Waleed Eissa
          wrote on last edited by
          #4

          Thanks guys for your replies, seems like I'll have to write myself .. just wanted to be sure I'm not wasting my time in reinventing the wheel ..

          Waleed Eissa Software Developer Sydney

          J 1 Reply Last reply
          0
          • W Waleed Eissa

            Thanks guys for your replies, seems like I'll have to write myself .. just wanted to be sure I'm not wasting my time in reinventing the wheel ..

            Waleed Eissa Software Developer Sydney

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Does SortedList in the System.Collections.Generic namespace not work for you? It has a GetByIndex method along with key lookup!

            W 1 Reply Last reply
            0
            • J J4amieC

              Does SortedList in the System.Collections.Generic namespace not work for you? It has a GetByIndex method along with key lookup!

              W Offline
              W Offline
              Waleed Eissa
              wrote on last edited by
              #6

              Thanks for your reply, actually I want to keep the same order in which items are inserted, this is why SortedListed and SortedDictionary are not suitable for the job ..

              Waleed Eissa Software Developer Sydney

              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