是否可以在队列中使用2D数组?窗户形式

时间:2012-01-28 08:01:36

标签: winforms for-loop queue multidimensional-array

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

我一直在尝试这个,但是visual studio给了我错误“对象引用未设置为对象的实例。”

1 个答案:

答案 0 :(得分:0)

您只分配双数组,您仍然需要为数组中的每个条目分配队列,如:

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