Collection object recommendation

B

Ben Amada

I would like to use one of .NET's collection or dictionary objects to store
various name-value pieces of data. I'm hoping that I can retrieve the
values from the collection by specifying the 'name'. Also, I would like to
be able to iterate through the collection (by index I guess) and retrieve
all the values in the collection. I realize that .NET supports a few
different types of these collection objects, but prefer to use the lightest
one possible as I may store the collection in viewstate (in an ASP.NET app)
and am trying to avoid the viewstate from getting too large.

Can anyone suggest a suitable collection object (e.g. hashtable or possibly
something else)?

Lastly, a link to an example of the collection's usage would be very
appreciated!

Thanks,
Ben
 
B

Ben Amada

Ken said:
Hi,

If you want to be able to look values up I would use a
hashtable.

Ken

Hi & Thanks! Couple of questions about the hashtable ... is it possible to
update a value stored in the hashtable? Or do I have to remove the value
first, then re-add it? And if you do have to remove the value first, then
re-add it, is there is a way to determine if a "key" has already been stored
in the hashtable -- like some type of "exists" function ... or would I have
to iterate through the hashtable to determine if the "key" has already been
added?

Appreciate your help!
Ben
 
H

Herfried K. Wagner [MVP]

Ben Amada said:
is there is a way to determine if a "key" has already been stored
in the hashtable -- like some type of "exists" function ...

'Hashtable.ContainsKey'.
 
A

alantolan

You can update the items in place for reference types.


Say you have a class Widget, and a Hashtable _widgets

_widgets = new HashTable
_widgets.add("Key", new Widget)

dim w as widget = _widgets("Key")
w.SomeValue = 17

updates the item in the hashtable.


Value types should work differently, though I haven't tried them out.

hth,
Alan.
 

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

Top