copy Hashtable values to another Hashtable?

  • Thread starter Thread starter M
  • Start date Start date
M

M

I am trying to copy the values of one hashtable to another.

I ran into a read only error when using the IDictionaryEnumerator.

while (myHashEnumerator.MoveNext()){
while (fsHashEnumerator.MoveNext()){
if (myHashEnumerator.Key == fsHashEnumerator.Key)
{
myHashEnumerator.Value = fsHashEnumerator.Value;
}
}
}


I have read somewhere on this group that the above doesn't work because
I am retrieving dictionary entries, not the actual key/value pairs.

Any help is appreciated.
 
M said:
I am trying to copy the values of one hashtable to another.

I ran into a read only error when using the IDictionaryEnumerator.

while (myHashEnumerator.MoveNext()){
while (fsHashEnumerator.MoveNext()){
if (myHashEnumerator.Key == fsHashEnumerator.Key)
{
myHashEnumerator.Value = fsHashEnumerator.Value;
}
}
}


I have read somewhere on this group that the above doesn't work because
I am retrieving dictionary entries, not the actual key/value pairs.

Any help is appreciated.
If you want a shallow copy, you can just use Clone() method on the
Hashtable. If not, you will need to iterate through the keys and
construct new objects out of the other ones.
 
Thank you...but...I need a deep copy, and I am struggling with the syntax.

Any help is definitely appreciated..perhaps an example...

Cheers!
 
M said:
Thank you...but...I need a deep copy, and I am struggling with the syntax.

Any help is definitely appreciated..perhaps an example...

Something like:

foreach (DictionaryEntry entry in hashtable)
{
object key = entry.Key;
object value = entry.Value;

// Now do something with that entry
}
 
Back
Top