爲什麼以下'exist'布爾變量的值爲false ???字典密鑰不包含已包含在密鑰中的密鑰
foreach (Cell existCell in this.decoratorByCell.Keys)
{
//this call yield the same hashcode for both cells. still exist==false
bool exist =
this.decoratorByCell.ContainsKey(existCell);
}
我重寫GetHashCode()方法&的equals()方法如下:
public override int GetHashCode()
{
string nodePath = GetNodePath();
return nodePath.GetHashCode() + m_ownerColumn.GetHashCode();
}
public bool Equals(Cell other)
{
bool nodesEqual = (other.OwnerNode == null && this.OwnerNode == null) || (other.GetNodePath() == this.GetNodePath());
bool columnsEqual = (other.OwnerColumn == null && this.OwnerColumn == null) || (other.OwnerColumn == this.OwnerColumn);
bool treesEqual = (this.m_ownerTree == other.m_ownerTree);
return (nodesEqual && columnsEqual && treesEqual);
}
.NET框架文檔實際上有一個更好的描述它必須做什麼,並澄清你的#1應該做的情況下:http://msdn.microsoft.com/en-us/library/system.object.gethashcode的.aspx – jasonh 2010-04-25 15:59:45