473,785 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 IDictionaryEnum erator.

while (myHashEnumerat or.MoveNext()){
while (fsHashEnumerat or.MoveNext()){
if (myHashEnumerat or.Key == fsHashEnumerato r.Key)
{
myHashEnumerato r.Value = fsHashEnumerato r.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 17159
M wrote:
I am trying to copy the values of one hashtable to another.

I ran into a read only error when using the IDictionaryEnum erator.

while (myHashEnumerat or.MoveNext()){
while (fsHashEnumerat or.MoveNext()){
if (myHashEnumerat or.Key == fsHashEnumerato r.Key)
{
myHashEnumerato r.Value = fsHashEnumerato r.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..pe rhaps 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******@hotma il.com> wrote:
Thank you...but...I need a deep copy, and I am struggling with the syntax.

Any help is definitely appreciated..pe rhaps an example...


Something like:

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

// Now do something with that entry
}

--
Jon Skeet - <sk***@pobox.co m>
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
10386
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 want thusly (this compiles, at least): Hashtable hTable = (Hashtable)hMaster; Hashtable hColumn = (Hashtable)hTable; return hColumn.ContainsKey(codeValue);
2
1403
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 c# or VB.NET? I don't want to use JScript. consFin = {2:'m',4:'n',6:'ng',8:'r',10:'l',12:'kh',14:'k',16:'s',18:'hl',19:'tl',20:'s
8
59519
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
16
696
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
1644
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
9199
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
348
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
3551
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. 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.
1
2513
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 hastables that is declared as a member of the class. Its creating a reference i'm guessing to the original element instead of copying just the actual values. How do I fix this? for(int i=0; i<Convert.ToInt32(Universe.Count*0.1); i++) ...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.