自定义两对象是否相等方法,必须用到GetHashCode方法,如
public class AirspaceCompareByUUID : IEqualityComparer<AIRSPACE_TS>
{
public bool Equals(AIRSPACE_TS x, AIRSPACE_TS y)
{
if (x == null || y == null)
return false;
if (x.AIRSPACE_UUID == y.AIRSPACE_UUID)
return true;
else
return false;
}
public int GetHashCode(AIRSPACE_TS obj)
{
if (obj == null)
return 0;
else
return obj.AIRSPACE_UUID.GetHashCode();
}
}
原文地址:https://www.cnblogs.com/mol1995/p/9160556.html
时间: 2024-10-08 11:54:32