配合lambda表达式 TypeList = TempShoppingMallItemList.Distinct(new ListComparer<ShoppingMallItem>((p1, p2) => p1.TypeItem == p2.TypeItem)).ToList();//去重 筛选类型
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();
}
}