测试方法:List<Jury> list = new List<Jury>();
Jury a = new Jury
{
UserId = 11,
UserName = "TT"
};
Jury b = new Jury
{
UserId = 11,
UserName = "TT"
};
list.Add(a);
list.Add(b);
var tt = list.Distinct(new JuryComparer());
自定义类: 裁判public class Jury
{
public int UserId { get; set; }
public string UserName { get; set; }
}
比较类:public class JuryComparer : IEqualityComparer<Jury>
{
public bool Equals(Jury x, Jury y)
{
return x.UserId.Equals(y.UserId);
}
public int GetHashCode(Jury obj)
{
return obj.GetHashCode();
}
}
FFIVE