Is it possible to use 2D Array on Queues? windows form

≡放荡痞女 提交于 2019-12-11 23:42:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!