By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,640 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,640 IT Pros & Developers. It's quick & easy.

Collection object recommendation

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

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

Ken
------------
"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:OI**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #2

P: n/a
Ken Tucker [MVP] wrote:
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
Nov 21 '05 #3

P: n/a
"Ben Amada" <be*@REpoMOweVErpick.com> schrieb:
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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

P: n/a

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.

Nov 21 '05 #5

P: n/a
Perfect -- thanks Herfried and Alan :)

Ben
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.