넓은 검색 우선 알고리즘을 미로 해석기로 사용하고 싶습니다. 미로는 TableLayoutPanel로 만들어집니다.어떻게 해시 테이블의 키 이름을 다르게 지정합니까?
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에 무언가를 추가 할 때마다 키의 이름을 변경해야한다고 생각합니다. 내 질문은 지금이다 : 나는 그것을 효율적으로 어떻게 하는가?