bandroo <ba*****@googlemail.comwrote:
How can I modify the items within a hashtable "in situ" so to speak?
At the moment, I am locating the item that I want, extracting it,
modifying the item, deleting the hashtable item, and then adding back
the modified item to hashtable.
This seems rather long winded, and surely there must be a simpler way
than that.
It depends:
1) Are you trying to modify the key or the value? Changing a key is
very dangerous, as a change which impacts the hashcode could render the
entry impossible to find.
2) If you're trying to modify the value, what type is the value? If
it's a reference type which lets you make the modification directly,
then you should be fine.
If it's a reference type which doesn't allow the appropriate
modification, or a value type (mutable or not, unless it's mutable via
an interface) you'll just have to change the value associated with the
key to the new one. You don't need to delete the previous value though.
Just do:
table[key] = modifiedValue;
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too