<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)!