473,466 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

deep copy (Clone) on System.Collections.Generic.Dictionary ?

Hi,
what is the best way to perform deep copy (Clone) on class that inherit from System.Collections.Generic.Dictionary ?
Dec 19 '06 #1
3 16740
Serialize and deserialise to a memory stream
Use a binary formater, its faster. You may have to implement a surrogate if
it isnt serialiazable and the contents will need to be too.
--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"semedao" wrote:
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from System.Collections.Generic.Dictionary ?
Dec 19 '06 #2
Hi,

If either the keys or values aren't serializable, or if you don't know
whether they will be, then iterate over the key-value pairs and copy them
into a new instance of your class. If the keys or values are ICloneable
then store the result of the Clone method, otherwise check whether they are
serializable and serialize/deserialize them as per Ciaran's response.

--
Dave Sexton

"semedao" <se*****@community.nospamwrote in message
news:eW**************@TK2MSFTNGP06.phx.gbl...
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?
Dec 19 '06 #3
Hi,

I should add that if you have typed the key and value as value-types then
you'll just have to iterate the dictionary and copy them into a new
instance - no ICloneable or serialization/deserialization required.

--
Dave Sexton

"semedao" <se*****@community.nospamwrote in message
news:eW**************@TK2MSFTNGP06.phx.gbl...
Hi,
what is the best way to perform deep copy (Clone) on class that inherit from
System.Collections.Generic.Dictionary ?
Dec 19 '06 #4

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

Similar topics

4
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)...
1
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...
4
by: Dennis | last post by:
I have several Data Structures, say "mystruct" which contain arrays of bytes, other structures, etc. I then dimension a variable (var1) as "mystruct" and set the various elements var1 to data. I...
5
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...
4
by: jjkboswell | last post by:
I have an XSD which I have generated a class from using the xsd.exe tool. My XSD contains complex types within it, so that the generated class has member variables which are of types that are also...
2
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: ...
4
by: Kyote | last post by:
I'm trying to persist a list of filenames. I've made a custom collection and a FileName class: 'Class to hold file name information Public Class FileNames Public fullName As String Public...
3
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...
3
by: gasfusion | last post by:
Hey guys. I have a little problem trying to clone my object, which is shown below. If you notice below, i am using a generic linked list structure to store byte arrays. The problem is when i use my...
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
jinu1996
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...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.