.Net equivalent of Scripting.Dictionary

  • Thread starter Thread starter Oenone
  • Start date Start date
O

Oenone

Could someone suggest a good native .Net collection object that provides
similar functionality to the COM Scripting.Dictionary 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?
 
Oenone said:
Could someone suggest a good native .Net collection object that provides
similar functionality to the COM Scripting.Dictionary 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.

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

Have you looked at SortedList?
 
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.
 
Would you have to create COM wrappers for all the classes you intended to
put into the dictionary?

--
Jonathan Allen


Jon said:
Why not just use Scripting.Dictionary? ;)

Jon
 
Something like

'Reference added to scrrun.dll via Add Reference

Dim dict As New Scripting.Dictionary

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 said:
Would you have to create COM wrappers for all the classes you intended to
put into the dictionary?
 
Thanks for all the suggestions.

I eventually plumped for the
System.Collections.Specialized.StringDictionary. 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top