.Net equivalent of Scripting.Dictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oenone

    #1

    .Net equivalent of Scripting.Dictionary

    Could someone suggest a good native .Net collection object that provides
    similar functionality to the COM Scripting.Dicti onary object?

    Specifically I need to be able to add items with an associated key, retrieve
    them by key or by index within the collection, and determine whether an item
    exists in the collection by querying with its key.

    The HashTable was looking good as it does virtually all of these things, but
    it doesn't seem to be possible to retrieve its items by index, which is
    something I need to be able to do.

    Any suggestions?

    --

    (O)enone


  • Larry Lard

    #2
    Re: .Net equivalent of Scripting.Dicti onary



    Oenone wrote:[color=blue]
    > Could someone suggest a good native .Net collection object that provides
    > similar functionality to the COM Scripting.Dicti onary object?
    >
    > Specifically I need to be able to add items with an associated key, retrieve
    > them by key or by index within the collection, and determine whether an item
    > exists in the collection by querying with its key.
    >
    > The HashTable was looking good as it does virtually all of these things, but
    > it doesn't seem to be possible to retrieve its items by index, which is
    > something I need to be able to do.[/color]

    I don't remember Dictionary being able to recover items by Index, but
    anyway.

    Have you looked at SortedList?

    --
    Larry Lard
    Replies to group please

    Comment

    • Robin Tucker

      #3
      Re: .Net equivalent of Scripting.Dicti onary

      I would derive from dictionarybase and encapsulate an arraylist inside the
      class. Sure, it would be more work, but in my experience these things are
      pretty fast anyway.

      "Oenone" <oenone@nowhere .com> wrote in message
      news:%23lxkTVRb FHA.3488@tk2msf tngp13.phx.gbl. ..[color=blue]
      > Could someone suggest a good native .Net collection object that provides
      > similar functionality to the COM Scripting.Dicti onary object?
      >
      > Specifically I need to be able to add items with an associated key,
      > retrieve them by key or by index within the collection, and determine
      > whether an item exists in the collection by querying with its key.
      >
      > The HashTable was looking good as it does virtually all of these things,
      > but it doesn't seem to be possible to retrieve its items by index, which
      > is something I need to be able to do.
      >
      > Any suggestions?
      >
      > --
      >
      > (O)enone
      >[/color]


      Comment

      • Jon

        #4
        Re: .Net equivalent of Scripting.Dicti onary

        Why not just use Scripting.Dicti onary? ;)

        Jon

        "Oenone" <oenone@nowhere .com> wrote in message
        news:%23lxkTVRb FHA.3488@tk2msf tngp13.phx.gbl. ..[color=blue]
        > Could someone suggest a good native .Net collection object that provides
        > similar functionality to the COM Scripting.Dicti onary object?
        >
        > Specifically I need to be able to add items with an associated key,
        > retrieve them by key or by index within the collection, and determine
        > whether an item exists in the collection by querying with its key.
        >
        > The HashTable was looking good as it does virtually all of these things,
        > but it doesn't seem to be possible to retrieve its items by index, which
        > is something I need to be able to do.
        >
        > Any suggestions?
        >
        > --
        >
        > (O)enone
        >[/color]


        Comment

        • Jonathan Allen

          #5
          Re: .Net equivalent of Scripting.Dicti onary

          Would you have to create COM wrappers for all the classes you intended to
          put into the dictionary?

          --
          Jonathan Allen


          "Jon" <Email_Address@ SomewhereOrOthe r.com> wrote in message
          news:OmZt5%23Rb FHA.3932@TK2MSF TNGP12.phx.gbl. ..[color=blue]
          > Why not just use Scripting.Dicti onary? ;)
          >
          > Jon
          >
          > "Oenone" <oenone@nowhere .com> wrote in message
          > news:%23lxkTVRb FHA.3488@tk2msf tngp13.phx.gbl. ..[color=green]
          >> Could someone suggest a good native .Net collection object that provides
          >> similar functionality to the COM Scripting.Dicti onary object?
          >>
          >> Specifically I need to be able to add items with an associated key,
          >> retrieve them by key or by index within the collection, and determine
          >> whether an item exists in the collection by querying with its key.
          >>
          >> The HashTable was looking good as it does virtually all of these things,
          >> but it doesn't seem to be possible to retrieve its items by index, which
          >> is something I need to be able to do.
          >>
          >> Any suggestions?
          >>
          >> --
          >>
          >> (O)enone
          >>[/color]
          >
          >[/color]


          Comment

          • Jon

            #6
            Re: .Net equivalent of Scripting.Dicti onary

            Something like

            'Reference added to scrrun.dll via Add Reference

            Dim dict As New Scripting.Dicti onary

            Dim frm As New Form1



            'Add data

            dict.Add("1", CObj(frm))



            'Retrieve data

            Dim a As Form1

            a = CType(dict.Item ("1"), Form1)

            a.ShowDialog()



            'Key Exists?

            Dim b As Boolean

            b = dict.Exists("1" )

            MsgBox(b)



            Jon





            "Jonathan Allen" <x@x.x> wrote in message
            news:#R9K1PTbFH A.3144@TK2MSFTN GP14.phx.gbl...[color=blue]
            > Would you have to create COM wrappers for all the classes you intended to
            > put into the dictionary?
            >
            > --
            > Jonathan Allen
            >
            >
            > "Jon" <Email_Address@ SomewhereOrOthe r.com> wrote in message
            > news:OmZt5%23Rb FHA.3932@TK2MSF TNGP12.phx.gbl. ..[color=green]
            > > Why not just use Scripting.Dicti onary? ;)
            > >
            > > Jon
            > >
            > > "Oenone" <oenone@nowhere .com> wrote in message
            > > news:%23lxkTVRb FHA.3488@tk2msf tngp13.phx.gbl. ..[color=darkred]
            > >> Could someone suggest a good native .Net collection object that[/color][/color][/color]
            provides[color=blue][color=green][color=darkred]
            > >> similar functionality to the COM Scripting.Dicti onary object?
            > >>
            > >> Specifically I need to be able to add items with an associated key,
            > >> retrieve them by key or by index within the collection, and determine
            > >> whether an item exists in the collection by querying with its key.
            > >>
            > >> The HashTable was looking good as it does virtually all of these[/color][/color][/color]
            things,[color=blue][color=green][color=darkred]
            > >> but it doesn't seem to be possible to retrieve its items by index,[/color][/color][/color]
            which[color=blue][color=green][color=darkred]
            > >> is something I need to be able to do.
            > >>
            > >> Any suggestions?
            > >>
            > >> --
            > >>
            > >> (O)enone
            > >>[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Oenone

              #7
              Re: .Net equivalent of Scripting.Dicti onary

              Thanks for all the suggestions.

              I eventually plumped for the
              System.Collecti ons.Specialized .StringDictiona ry. Accessing the objects by
              index isn't quite as easy as it might be (I have to use the Keys.CopyTo()
              method to copy all the keys to an array, and then can access the keys by
              index) but it pretty much does what I need.

              --

              (O)enone


              Comment

              Working...