对象比较,集合元素比较的类库 using System;using System.Collections.Generic;using System.Linq;using System.Text;using CompareObjectsNet;namespace CompareNetObjDemo{ class Program { static void Main(string[] args) { Test1(); Console.WriteLine("完成"); Console.ReadKey(); } static void Test1() { //创建比较对象的类型 CompareLogic compareLogic = new CompareLogic(); //创建2个不同的Person类型 Person person1 = new Person(); person1.DateCreated = DateTime.Now; person1.Name = "Jorn"; person1.Age = 25; Person person2 = new Person(); person2.Name = "Greg"; person2.DateCreated = DateTime.Now; person2.Age = 22; //设置比较对象的配置文件,最大不同点为3 compareLogic.Config.MaxDifferences = 2; //获取比较结果,使用Compare方法 ComparisonResult result = compareLogic.Compare(person1, person2); //如果不相等,输出不同信息字符串 if (!result.AreEqual) Console.WriteLine(result.DifferencesString); } } public class Person { public String Name { get; set; } public Int32 Age { get; set; } public DateTime DateCreated { get; set; } }}
评论