唯一對象我有一個Person類:獲得使用LINQ
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"
使用不同會給
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"
只有那些不重複的人物。
問候。
謝謝。這工作:) – Codehelp 2013-02-28 10:24:51