标签:ram isa list 不同 shc equal als int compare
class Program
{
static void Main(string[] args)
{
List<People> peoples = new List<People>
{
new People{ ID=1,Name="xxx" },
//new People{ ID=1,Name="xxx" },
new People{ID=2,Name="yyy" },
};
peoples = peoples.Distinct(new Filter()).ToList();
Console.WriteLine("Hello World!" + peoples.Count);
}
}
public class Filter : IEqualityComparer<People>
{
public bool Equals([AllowNull] People x, [AllowNull] People y)
{
Console.WriteLine($"Equals->{x.ID},{y.ID}");
return x.ID == y.ID;
}
public int GetHashCode([DisallowNull] People obj)
{
Console.WriteLine($"GetHashCode->{obj.ID}");
return obj.ID;
}
}
IEqualityComparer
IEqualityComparer<TSource> 比较规则
标签:ram isa list 不同 shc equal als int compare
原文地址:https://www.cnblogs.com/chasingdreams2017/p/13972414.html