1. TerminalModel 类
public class TerminalModel
{
public string Code{get;set;}
public string Name{get;set;}
}
2. CompareTerminalModel 类
public class CompareTerminalModel : IEqualityComparer<TerminalModel>
{
public bool Equals(TerminalModel x, TerminalModel y)
{
return x.Code == y.Code;
}
public int GetHashCode(TerminalModel p)
{
if (p == null)
return 0;
return p.Code.GetHashCode();
}
}
3. 取集
List<TerminalModel> list = new List<TerminalModel>();
List<TerminalModel> list2 = new List<TerminalModel>();
var chaji = list.Except(list2,new CompareTerminalModel()).ToList(); //差集
var jiaoJi = list.Intersect(list2,new CompareTerminalModel()).ToList(); //交集
var bingJi = list.Union(list2,new CompareTerminalModel()).ToList(); //并集