泛型List去除重复指定字段ID
var list=listTemp.Distinct(new IDComparer ()).ToList();
重写比较的方法:
public class IDComparer : IEqualityComparer<T>
{
public bool Equals(T x, T y)
{
if (x == null)
return y == null;
return x.ID == y.ID;
}
public int GetHashCode(T obj)
{
if (obj == null)
return 0;
return obj.ID.GetHashCode();
}
}
参考链接:http://blog.csdn.net/yang651280121/article/details/8259097