问题
Queue[,] inventqueue = new Queue[10,7];
for(int row = 0; row < inventqueue.GetLength(0); row++)
{
for (int col = ; col < inventqueue.GetLength(1); col++)
{
if(inventqueue[row,col].Count != 0)
{
MessageBox.Show("Theres a queue on " + row + "," + col);
}
}
}
I have been trying this out but visual studio is giving me the error "Object reference not set to an instance of an object."
回答1:
You're allocating only the double array, you still need to allocate Queues for each entry in the array like:
Queue[,] inventqueue = new Queue[10,7];
for(int row = 0; row < inventqueue.GetLength(0); row++)
{
for (int col = ; col < inventqueue.GetLength(1); col++)
{
inventqueue[row,col] = new Queue();
}
}
来源:https://stackoverflow.com/questions/9043822/is-it-possible-to-use-2d-array-on-queues-windows-form