Dictionary keys don't contain a key that's already contained in keys

Posted by ran on Stack Overflow See other posts from Stack Overflow or by ran
Published on 2010-04-25T10:54:42Z Indexed on 2010/04/25 11:03 UTC
Read the original article Hit count: 367

Why is the following 'exist' boolean variable getting a value of 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);
}

I've overridden GetHashCode() & Equals() Methods as follows:

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);
}

© Stack Overflow or respective owner

Related posts about dictionary

Related posts about keys