Copy a hashtable

  • Thread starter Thread starter Ray Cassick \(Home\)
  • Start date Start date
R

Ray Cassick \(Home\)

I have a hashtable in a class that contains key (strings) value (integers,
strings, longs, etc...) data pairs.

I want to move the data to another (different) class instance for
processing.

The key is that I want to make sure I don't rely on the first class to stay
around so I want to make sure that when I move (copy) the data from one
class to another I get a REAL copy, not just a reference to the node in the
first hashtable.

Basic looks of what I would like is below:

Public class Foo

private mDatastore as new hashtable

public sub AddData(. . .)
 
Ray,

If you can guarentee that the items in the dictionary implement
ICloneable then you can do the following.

For Each item as DictionaryEntry in sourceDictionary
Dim cloneable as ICloneable = DirectCast(item.Value, ICloneable)
destinationDictionary.Add(item.Key, cloneable.Clone())
Next

Brian
 

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