Tuesday, June 23, 2009

Generics Dictionary<> clone

Here's a simple routine that will clone generic Dictionary:


public static Dictionary<S, V> Clone<S,V>(Dictionary<S, V> dictionary)
{
Dictionary<S, V> cloneDictionary = new Dictionary<S, V>();
foreach (KeyValuePair<S, V> kvp in dictionary)
cloneDictionary.Add(kvp.Key, kvp.Value);

return cloneDictionary;
}

No comments: