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(. . .) 2 3551
Ray,
The most simple way to deepcopy an object is first to serialize it and than
to deserialize it. Here a sample for an arraylist. It has for that to
implement Iserializable http://www.vb-tips.com/default.aspx?...c-61641f5c8d9d
The hashtable implements Iserializable as well.
I hope this helps,
Cor
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 sourceDictionar y
Dim cloneable as ICloneable = DirectCast(item .Value, ICloneable)
destinationDict ionary.Add(item .Key, cloneable.Clone ())
Next
Brian
Ray Cassick (Home) wrote: 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(. . .) . . .
public function GetData() as hashtable return mDatastore
end function
End Class
FooInstance.Add Data("Key1", value1) FooInstance.Add Data("key2", value2)
Public class Bar
private mLocalData as new hashtable
mLocalData = FooInstance.Get Data()
End Class
... but I have a feeling that this is going to simply get my mLocalData set up with references to the nodes in the mDatastore hashtable and not what I want.
I even though about walking the hashtable returned by the GetData function (using a for each and a dictionary entry object) then just adding them to the mLocalData instance but was not sure that would do it either...
any ideas? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
}
|
by: francois |
last post by:
First of all I would to to apologize for resending this post again but I
feel like my last post as been spoiled
Here I go for my problem:
Hi,
I have a webservice that I am using and I would like it to return an XML
serialized version of an object.
|
by: Cyrus |
last post by:
I have a question regarding synchronization across multiple threads for a
Hashtable. Currently I have a Threadpool that is creating worker threads
based on requests to read/write to a hashtable. One function of the
Hashtable is to iterate through its keys, which apparently is inherently not
thread-safe. Other functions of the Hashtable include
adding/modifying/deleting.
To solve the synchronization issues I am doing two things:
1. Lock...
|
by: Ken |
last post by:
I have a C# Program where multiple threads will operate on a same Hashtable.
This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable)
method, so no further Lock statements are used before adding, removing or
iterating the Hashtable. The program runs in a high workload environment.
After running a few days, now it suddenly catchs this Exception when
inserting a pair of key and object,
stacktrace =...
|
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.
| |
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();
}
|
by: BenW |
last post by:
Hello,
What is the easiest way to make "deep copy" of my Hashtable?
How about with other Collection classes in C#, any documents available?
I don'r actually understand why Framework's Collection classes does not
support deep copy methods
by theself, only Clone with shallow copy.
|
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++)
...
|
by: PAzevedo |
last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from
multiple threads, now the Hashtable object is thread safe for reading,
but not for writing, so I lock the object every time I need to write to
it, but now it occurred to me that maybe I could just lock one of the
Hashtables inside without locking the entire object, but then I thought
maybe some thread could instruct the outside Hashtable to remove an
inside Hashtable...
|
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,...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |