473,796 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hashtable deep copy

7 New Member
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[ i ]. 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?

Expand|Select|Wrap|Line Numbers
  1.             for(int i=0; i<Convert.ToInt32(Universe.Count*0.1); i++)
  2.             {    
  3.                 Hashtable company_data = new Hashtable();
  4.                 company_data = (Hashtable)Universe[ i ];
  5.                 Hashtable dm = report.DownloadMnemonics_pri();    
  6.                 foreach(string key in dm.Keys)
  7.                 {
  8.                     company_data.Add(key,GetFactSetData(company_data["ticker"].ToString(),dm[key].ToString()));
  9.                 }
  10.  
  11.                 report.Add(company_data);
  12.                 ReportProgressToClient(i,Convert.ToInt32(Universe.Count*0.1),"FactSet Download: " + company_data["ticker"].ToString(), ProgressType.CURRENT_PROGRESS);
  13.                 dm = null;
  14.                 company_data = null;
  15.                 GC.Collect();
  16.                 GC.WaitForPendingFinalizers();
  17.             }
  18.  
Thanks for the help.
Oct 6 '06 #1
1 2513
TheVillain9
7 New Member
Answer:

(Universe[i] as Hashtable).Clon e() as Hashtable
Oct 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3288
by: Tony Johansson | last post by:
Hello! I'm reading in a book about C++ and that is something that sound strange. It says "Pointers have reference-assignment semantics similar to those in Java. For example, after the assignment Student* john = michael; both john and michael share the same object. This type of an assignment is different then value-assignmnet semantics used by class variables, as in
3
17168
by: M | last post by:
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; }
3
1288
by: A. Burch | last post by:
I'm wanting to use a Hashtable. I have 2 (keys, objectvalues) pairs of data to store. I'm using a static declartion for the Hashtable the instance of the class that is the object. If I try and retreive the first object after storing after the 2 (key, objectvalues) are stored I always get the last object value stored. Why doesn't qrec = (Q)HT give a copy of the last or in this code the second of the 2 objects? How should the code be...
3
4892
by: A. Burch | last post by:
I posted early about Hashtable use and the shallow/deep copy and storing a reference answered that question. I've got a larger implementation of this, but am not sure why I'm getting this error. Object reference not set to an instance of an object. I don't know what I'm missing. What needs to be fixed for this implementation to work? using System; using System.Collections;
4
52311
by: fperfect13 | last post by:
Hi, I wanted to perform a deep copy of an array. Searching on google I ran into different opinions : C# Interview Questions (http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx) 10.What's the difference between the System.Array.CopyTo() and System.Array.Clone()?
3
9695
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList atemp = new ArrayList(); // THE ARRAY StreamWriter sw = new StreamWriter(@"C:\temp\fred.html");
1
2338
by: oDDskOOL | last post by:
I realized today that the Hashtable.Clone only produces a shallow copy... that makes me go mad that M$ doesn't even provide a deep copy ctor for the Hashtable class ! mighty tech ducks might reply "oh but what if the types in hastable don't have copy ctors defined? that could lead to dangerous situations". well, but was it a significant effort to provide a copy ctor / deep clone method to this class for objects that provide the...
2
1220
by: Curtis | last post by:
Does anyone have any examples of serializing a hashtable? I tried to make a copy of the hash table using the .clone method but per MS documention it creates a shallow copy of the object. I am trying to make a full or deep copy of the master hashtable any examples would be great. Thanks, Curtis
3
8752
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp) My question, coming from a C++ background where deep copying is done, is why in C# you would do either deep or shallow copying as suggested by O'Reilly (using the "ICloneable" inhereited interface), at least for the .NET framework. ...
0
9528
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
10455
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
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
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
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
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
3
2925
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.