我正在将两个List<Dictionary<string, object>>与我自己的IEqualityComparer<Dictionary<string, object>>实现进行比较,但是 GetHashCode 和 Equals 方法都没有被调用。这是我自己的 IEqualityComparer 实现。public class TestEqualityComparer : IEqualityComparer<Dictionary<string, object>>{ public bool Equals(Dictionary<string, object> a, Dictionary<string, object> b) { return true; // breakpoint here } public int GetHashCode(Dictionary<string, object> obj) { return 0; // breakpoint here }}这是一个实际的比较代码。var a = new List<Dictionary<string, object>>();var b = new List<Dictionary<string, object>>();a.Add(new Dictionary<string, object> { ["id"] = 1, ["msg"] = "aaaaa" });a.Add(new Dictionary<string, object> { ["id"] = 2, ["msg"] = "bbbbb" });a.Add(new Dictionary<string, object> { ["id"] = 3, ["msg"] = "ccccc" });b.Add(new Dictionary<string, object> { ["id"] = 1, ["msg"] = "zzzzz" });b.Add(new Dictionary<string, object> { ["id"] = 2, ["msg"] = "bbbbb" });b.Add(new Dictionary<string, object> { ["id"] = 4, ["msg"] = "ddddd" });var except = a.Except(b, new TestEqualityComparer());当我运行上面的代码时,断点从未被触发。有什么问题?
1 回答
- 1 回答
- 0 关注
- 140 浏览
添加回答
举报
0/150
提交
取消