C#自定义规则对比两个集合的对象是否相等

IList<获取的类> ret = 类的结果集;
            return ret.Except(另一个相同类型的对象列表集, new AClassComPare());

public class AClassComPare : IEqualityComparer<AClass>
    {
        /// <summary>
        /// 这里是自定义的规则,如果返回true证明相等
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool Equals(AClass x, AClass y)
        {
            if (x.OrderNo == y.OrderNo && x.ID == y.ID && x.BID == y.BID)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 这里是继承的接口类,不必修改
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int GetHashCode(AClass obj)
        {
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return obj.ToString().GetHashCode();
            }
        }
    }

 

posted @ 2018-08-29 14:50  洛晨随风  阅读(777)  评论(0编辑  收藏  举报