我想做广度优先搜索算法作为迷宫求解器。迷宫是由一个TableLayoutPanel构成的。如何以不同的方式命名Hashtable中的按键
我有这样的事情:
Hashtable hash = new Hashtable();
Queue<TableLayoutPanelCellPosition> q_cellposition = new Queue<TableLayoutPanelCellPosition>();
while (q_cellposition.Count != 0)
{
TableLayoutPanelCellPosition currentPosition = q_cellposition.Dequeue();
TableLayoutPanelCellPosition left = new TableLayoutPanelCellPosition(currentPosition.Column - 1, currentPosition.Row);
Label leftN = (Label)tlp.GetControlFromPosition(left.Column, left.Row);
TableLayoutPanelCellPosition right = new TableLayoutPanelCellPosition(currentPosition.Column + 1, currentPosition.Row);
Label rightN = (Label)tlp.GetControlFromPosition(right.Column, right.Row);
hash.Add(leftN, currentPosition);
q_cellposition.Enqueue(left);
hash.Add(rightN, currentPosition);
q_cellposition.Enqueue(right);
}
现在,在第一次迭代之后,它显然试图将新KeyValuePair添加到哈希表。然而,它将新的leftN键和rightN键看作相同的标签(尽管它们在技术上不是这样),并且它引发了错误,即该键已被添加。我想我每次向Hashtable添加内容时都必须更改密钥的名称。我现在的问题是:我如何有效地做到这一点?