C # DataRow Comparison

Source: Internet
Author: User
  <summary>//DataRow comparison///</summary>//<param name= "DrA" ></param>        <param name= "DrB" ></param>///<param Name= "ColumnNames" > column names to be compared </param> <returns></returns> public static bool Datarowcompare (DataRow DrA, DataRow DrB, string[] ColumnName            s) {bool flag = false;            Column sort Columnsort (DrA, columnnames) that needs to be compared in a DataRow;            Columnsort (DrB, columnnames);                foreach (DataColumn DcA in DrA.Table.Columns) {if (Columnnames.contains (dca.columnname))  {foreach (DataColumn DcB in drB.Table.Columns) {if                        (Columnnames.contains (Dcb.columnname))                                {if (Dcb.columnname = = dca.columnname)//column name comparison {                      Type comparison          if (dcb.datatype! = dca.datatype) {flag = FAL                                    Se                                Break }//Value compare else if (Compareobject (Dra[dcb.columnname], DRB[DCB.                                    ColumnName]) {flag = true;                                Break }}}}} Retu        RN Flag; }///<summary>///In the order of the column names in the array///</summary>//<param name= "DrA" ></param >//<param name= "ColumnNames" > Sort by column name in array </param> public static void Columnsort (DataRow DrA            , string[] columnnames) {//dra sort int i = 0; foreach (String columnName in ColumnNames)           {if (DrA.Table.Columns.Contains (ColumnName)) {DrA.Table.Colu Mns[columnname].                    Setordinal (i);                i++; }            }        }


Object Comparison method Compareobject (object Obja, Object OBJB):

C # Object Comparisons (value types, reference types)

Deep Copy Part code:

C # entity class serialization and deserialization one (XmlSerializer)

C # entity class serialization and deserialization two (DataContractSerializer)

The above is the C # DataRow comparison content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.