为了账号安全,请及时绑定邮箱和手机立即绑定

关于join IEqualityComparer<T> 查询的问题

关于join IEqualityComparer<T> 查询的问题

阿晨1998 2018-12-07 06:14:45
有2个比较器: public class EqualityComparer123 : IEqualityComparer { Func pred; public EqualityComparer123(Func pred) { this.pred = pred; } public bool Equals(ClassA x, ClassA y) { //return x.id == y.id; return pred(x, y); } public int GetHashCode(ClassA obj) { return base.GetHashCode(); } } public class TEqualityComparer : IEqualityComparer { Func pred; public TEqualityComparer(Func pred) { this.pred = pred; } public bool Equals(T x, T y) { return pred(x, y); } public int GetHashCode(T obj) { return obj.GetHashCode(); } }       类有: public class ClassA { public int id { set; get; } public string name { set; get; } }   代码: var ca = new List(); ca.Add(new ClassA() { id = 1, name = "nima" }); ca.Add(new ClassA() { id = 2, name = "tama" }); var cb = new List(); cb.Add(new ClassA() { id = 1, name = "nima2" }); cb.Add(new ClassA() { id = 3, name = "tama2" }); var Compare = new EqualityComparer123((x, y) => { return x.id == y.id; }); var query = ca.Join(cb, x => x, y => y, (x, y) => new { CA = x, CB = y }, Compare); var Compare3 = new TEqualityComparer((x, y) => { return x.id == y.id; }); var query3 = ca.Join(cb, x => x, y => y, (x, y) => new { CA = x, CB = y }, Compare3);   其中query1能够查询出数据,而query3却查询不出数据,望解惑。。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 511 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信