1、定义对象
public class BusinessObj
{
public string OtherData;
public int Key;
}
{
public string OtherData;
public int Key;
}
2、自定义比较符
public class BusinessObjComparer : IEqualityComparer<BusinessObj>
{
public bool Equals(BusinessObj source, BusinessObj dest)
{
return source.Key == dest.Key;
}
public int GetHashCode(BusinessObj obj)
{
return obj.Key.GetHashCode();
}
}
{
public bool Equals(BusinessObj source, BusinessObj dest)
{
return source.Key == dest.Key;
}
public int GetHashCode(BusinessObj obj)
{
return obj.Key.GetHashCode();
}
}
3、使用
List<BusinessObj> curBusinessObjList =
curBusinessObjList.FindAll((BusinessObj curBusinessObj) => (curBusinessObj.Key != 1)).Distinct(new BusinessObjComparer()).ToList();
curBusinessObjList.FindAll((BusinessObj curBusinessObj) => (curBusinessObj.Key != 1)).Distinct(new BusinessObjComparer()).ToList();