473,413 Members | 1,799 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,413 software developers and data experts.

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 16738
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...

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.