How can i copy Dictionary object by value in c#
+1
A:
Create a new Dictionary
passing the source dictionary in the constructor (of course, this will not copy the objects in the dictionary if they are reference types):
var copied = new Dictionary<KeyType, ValueType>(originalDictionary);
Mehrdad Afshari
2010-01-16 21:46:31
thanks, it's work nice
hippout
2010-01-16 21:50:25
A:
There is no intrinsic method to do that. You'll have to do it manually.
The first step is to decide how deep you want the copy to pair. Do you want separate Dictionary entry object holding references to common keys & values, Or do you want everything copied. If the latter, they would need to implement ICloneable to create a general purpose method.
James Curran
2010-01-16 21:49:12
Warning! Just because a class implements `ICloneable` does not mean that `Clone` performs a deep copy.
Jason
2010-01-16 21:51:09