473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

copy Hashtable values to another Hashtable?

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.
Nov 15 '05 #1
3 17127
M wrote:
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.

--
Girish Bharadwaj

Nov 15 '05 #2
M
Thank you...but...I need a deep copy, and I am struggling with the syntax.

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

Cheers!

Girish Bharadwaj wrote:
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.


Nov 15 '05 #3
M <mi******@hotmail.com> wrote:
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
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matt C. | last post by:
I bet I know the answer already. I have a hashtable (hMaster) that holds several hashtables ("hTables") each of which holds other hashtables ("hColumns"). Presently, I am getting at the info I...
2
by: mark4asp | last post by:
Hello, I am converting an app from JavaScript to ASP.NET I have the following JavaScript 'associative array'. Is there a concise way to create an analogous structure in .NET Framework using...
8
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
16
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
1
by: Ryan Liu | last post by:
Hashtable.GetEnumerator is not thread safe, but what about I write I loop go though Hashtable.Values, is that thread saft? Thanks a lot!
6
by: harvie wang | last post by:
Hi, I want to implement a copy construct class, but the class have as Hashtable,how to do? public class A { private Hashtable _data; public A() { _data = new Hashtable(); }
10
by: SK | last post by:
Hey, i have a hashtable, where I am adding some values. Now when I iterate through them then they start in reverse order, why is that happening and how can I get rid of it? Thanks
2
by: Ray Cassick \(Home\) | last post by:
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. ...
1
by: TheVillain9 | last post by:
I'm adding key-values to my hashtable (company_data), but everytime I add something new, it adds it to the element from which the hashtable was derived, Universe. Universe is just an arraylist of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.