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();

  

posted @ 2017-01-10 11:44  炎蓝刀锋  阅读(202)  评论(0编辑  收藏  举报

生活中快乐要多一点!