我有這個二維數組或結構如何檢查二維數組中的密鑰對是否存在?
public struct MapCell
{
public string tile;
}
public MapCell[,] worldMap;
但是沒有辦法檢查密鑰對存在這個數組中或不...對於沒有可用的方法。
我試圖做這樣
if (worldMap[tileX, tileY] != null) {
}
它不工作:
Error 1 Operator '!=' cannot be applied to operands of type 'Warudo.MapCell' and '<null>'
和
if (worldMap[tileX, tileY].tile != null) {
它不工作,要麼(異常彈出時擊中不存在的元素)。
Index was outside the bounds of the array.
那麼,如何檢查密鑰對是否存在?
你必須使用數組嗎?也許類似字典的集合類將爲您提供您正在尋找的功能。 –
FishBasketGordo
2011-06-06 19:08:21
@FishBasketGordo ummm,它可以用作二維數組嗎?它會提供檢查方法嗎? – NewProger 2011-06-06 19:11:44
爲什麼你使用一個結構?可變的結構是一個壞主意......我可能會在這裏推薦一門課。 – 2011-06-06 19:11:59