110,532
社区成员
发帖
与我相关
我的任务
分享
List<photo> listPhoto;
var query = from p in listPhoto
group p by p.UserId into g
where g.Count() == 1
select g;
private class PhotoComparer : IEqualityComparer<Photo>
{
public bool Equals(Photo x, Photo y)
{
return x.UserId == y.UserId && x.UserName == y.UserName ;
}
public int GetHashCode(Photo obj)
{
if (obj == null)
{
return 0;
}
else
{
return obj.ToString().GetHashCode();
}
}
}
list = list.Distinct(new PhotoComparer ()).ToList(); <--这个就是了你要的唯一