In C #, using hashtable,datatable and so on to copy and clone

Source: Internet
Author: User

If there is a similar, very proud, if reproduced, please specify

In C #, with hashtable,datatable and so on replication and cloning, the following directly see examples

HashTable ht = NULL;

HT = new HashTable ();

foreach (string s in HT)

{

//...

}

It is necessary to modify the key values in the Hashtable when the above is traversed, it is common to report the exception, prompting your collection to modify XXX or something, because the collection in the back of the Foreach loop cannot be changed.

This time should I think of, should be in the traversal before copying a copy,

HashTable ht2 = new HashTable ();

Ht. Copy (ht2,0);

The above code can be debugged through, but the problem comes again, when I modified the ht2 in the key value, found that the key in HT also modified, obviously this is not the result I want, and then slightly thinking, with the Clone ()

Problem solving,

(DataTable also, datatable DT2 = dt.) Copy () or directly to the value is not possible, the same will change the value in the original datatble, ... Not to be continued ...

In C #, using hashtable,datatable and so on to copy and clone

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.