基本值类型
代码语言:javascript复制 public static List<T> GetListDiff<T>(List<T> listA,List<T> listB)
{
List<T> ret = new List<T>();
if (listA.Count > listB.Count)
ret = listA.Except(listB).ToList();
else {
ret = listB.Except(listA).ToList();
}
return ret;
}
对象类型
代码语言:javascript复制public class DiffDevlopments : IEqualityComparer<Devlopments>
{
public bool Equals(Devlopments x, Devlopments y)
{
return x.id == y.id;
}
public int GetHashCode(Devlopments obj)
{
if (obj == null)
{
return 0;
}
else
{
return obj.ToString().GetHashCode();
}
}
}
代码语言:javascript复制 List<Devlopments> listDiff = DataMgr.m_listDevlopments.Except(newDeve, new DiffDevlopments()).ToList();//差集
注意:长的list在前