【发布时间】:2012-04-14 16:29:38
【问题描述】:
我有一个类似的类:
public class Int16_2D
{
public Int16 a, b;
public override bool Equals(Object other)
{
return other is Int16_2D &&
a == ((Int16_2D)other).a &&
b == ((Int16_2D)other).b;
}
}
这适用于HashSet<Int16_2D>。但是在Dictionary<Int16_2D, myType> 中,.ContainsKey 在不应该返回 false 时返回。我在== 的实现中遗漏了什么吗?
【问题讨论】:
-
请注意,您实际上并没有实现
==,Equals()是不同的。
标签: c# class hashmap equality hashset