HashTable clone method

Posted by Akiii under C# category on | Points: 40 | Views : 2898
HashTable clone method provides a shallow copy. Now what is a shallow copy ?

The answer is a Shallow copy means copy the object values and not their reference. In other word if you change the copied data it will reflect at original place also.

class Program
static void Main(string[] args)
Hashtable EmpHashTable = new Hashtable();
EmpHashTable.Add("Key1", "Anirban");
EmpHashTable.Add("Key2", "Sharad");
EmpHashTable.Add("Key3", "Akiii");
string str = string.Empty;

Hashtable myShallowCopyObject = (Hashtable)EmpHashTable.Clone();

foreach (DictionaryEntry Temp in myShallowCopyObject)
str += ", " + Temp.Key + " - " + Temp.Value;

Thanks and Regards

Comments or Responses

Login to post response