Unity 小技巧之 自定义List.Distinct去重

  配合lambda表达式  TypeList = TempShoppingMallItemList.Distinct(new ListComparer<ShoppingMallItem>((p1, p2) => p1.TypeItem == p2.TypeItem)).ToList();//去重 筛选类型
Unity 小技巧之 自定义List.Distinct去重
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;


public class ListComparer<T> : IEqualityComparer<T>
{
    public delegate bool EqualsComparer<F>(F x, F y);

    public EqualsComparer<T> equalsComparer;

    public ListComparer(EqualsComparer<T> _euqlsComparer)
    {
        this.equalsComparer = _euqlsComparer;
    }

    public bool Equals(T x, T y)
    {
        if (null != equalsComparer)
        {
            return equalsComparer(x, y);
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(T obj)
    {
        return obj.ToString().GetHashCode();
    }
}

上一篇:【Linux】JDK+Eclipse 搭建C/C++开发环境


下一篇:自动化 CI&CD 与灰度发布|学习笔记