我有一个人类:
Public Class Person
{
public string Name {get; set;}
public string Id {get; set;}
}
Public EqualityOnPerson : IEqualityComparer<Person>
{
public bool Equals(PersonData x, PersonData y)
{
return x.Id == y.Id;
}
public int GetHashCode(Person obj)
{
return obj.Id.GetHashCode();
}
}
我有一个包含重复 ID 的人员对象列表:
Person.Name = "ABC"
Person.Id = "123"
Person.Name = "CBA"
Person.Id = "123"
Person.Name = "DEF"
Person.Id = "456"
Person.Name = "GHI"
Person.Id = "789"
Person.Name = "JKL"
Person.Id = "789"
Person.Name = "MNO"
Person.Id = "789"
Person.Name = "PQR"
Person.Id = "101"
Person.Name = "STU"
Person.Id = "102"
使用 distinct 将给出
Person.Name = "CBA"
Person.Id = "123"
Person.Name = "DEF"
Person.Id = "456"
Person.Name = "GHI"
Person.Id = "789"
Person.Name = "PQR"
Person.Id = "101"
Person.Name = "STU"
Person.Id = "102"
我怎么得到这个
Person.Name = "DEF"
Person.Id = "456"
Person.Name = "PQR"
Person.Id = "101"
Person.Name = "STU"
Person.Id = "102"
只有那些不重复的人对象。
问候。