日期:2014-05-17 浏览次数:20720 次
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(); <--这个就是了你要的唯一
List<photo> listPhoto;
var query = from p in listPhoto
group p by p.UserId into g
where g.Count() == 1
select g;