List集合去重的一种方法

public class ComparerHelper : IEqualityComparer<Model>
    {
        public bool Equals(Model x, Model y)
        {
            return x.Name== y.Name;
        }
        public int GetHashCode(Model obj)
        {
            return obj.Title.GetHashCode();
        }
    }
//调用
modelList = modelList.Distinct(new ComparerHelper()).ToList();

  

原文地址:https://www.cnblogs.com/sdaulldd/p/6268798.html