自定义条件判断两对象相等Equals的方法

自定义两对象是否相等方法,必须用到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();
        }
    }

posted on 2018-06-09 19:07  mol1995  阅读(580)  评论(0编辑  收藏  举报

导航