C # Introduction to replication and cloning
If there are similarities, we will be honored. If you reprint them, please note
In C #, we will talk about using HashTable, DataTable, and other copies and clones. Let's look at the example below.
HashTable ht = null;
Ht = new HashTable ();
Foreach (string s in ht)
{
//...
}
// The key value in HashTable needs to be modified during the previous traversal. Generally, an exception is reported, prompting you that the set has been changed to XXX or something, because the set after in cannot be changed during foreach traversal.
// I should have thought of it at this time. I should copy it before convenience,
HashTable ht2 = new HashTable ();
Ht. Copy (ht2, 0 );
The above code can be debugged, but the problem arises. After I modified the key value in ht2, I found that the key value in ht was also modified, obviously this is not the result I want, and then I think a little bit, using Clone ()
Problem solving,
(Same as DataTable, DataTable dt2 = dt. Copy () copying or directly giving a value is not acceptable, it will also change the value in the original datatble,)... not complete...
// Here, you need to modify the key value in HashTable. Generally, an exception is reported, prompting you that your set has been modified XXX or something, because the set after in cannot be changed during foreach traversal.
// I should have thought of it at this time. I should have copied one copy before convenience.