泛型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

 

相关文章:

  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-09-21
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2021-06-14
  • 2021-06-14
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案