一、定义
1、Falcon_PumpX_Equal_Comparer :类名,随便取名
2、IEqualityComparer:必须继承这个接口
3、Falcon_PumpX:需要去重的对象
4、IEqualityComparer、GetHashCode 是接口必须实现的方法
private class Falcon_PumpX_Equal_Comparer : IEqualityComparer<Falcon_PumpX>
{
bool IEqualityComparer<Falcon_PumpX>.Equals(Falcon_PumpX x, Falcon_PumpX y)
{
return x.Part_No.Trim() == y.Part_No.Trim() && x.Serial_No.Trim() == y.Serial_No.Trim();
}
public int GetHashCode(Falcon_PumpX obj)
{
return obj.Serial_No.Length;
}
}
二、使用方法
Falcon_PumpX_Equal_Comparer com = new Falcon_PumpX_Equal_Comparer();
var list = ((Param_QM_Lab_CheckResult_Imp)Param).Falcon_Pump_List.Distinct(com);