是否有可能在队列上使用二维数组?窗体窗体 [英] Is it possible to use 2D Array on Queues? windows form

查看:401
本文介绍了是否有可能在队列上使用二维数组?窗体窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 队列[,] inventqueue = new Queue [10,7]; (int col =; col< inventqueue.GetLength(1); col ++)为(int row = 0; row< inventqueue.GetLength(0); row ++)
{


{
if(inventqueue [row,col] .Count!= 0)
{
MessageBox.Show(Theres a queue on+ row +,+ col );





$ b我一直在尝试但Visual Studio给我的错误对象引用未设置为一个对象的实例。。只有double数组,您仍然需要为数组中的每个条目分配队列,如:

  Queue [,] inventqueue = new队列[10,7]。 (int col =; col< inventqueue.GetLength(1); col ++)为(int row = 0; row< inventqueue.GetLength(0); row ++)
{


{
inventqueue [row,col] = new Queue();
}
}


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."

解决方案

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

这篇关于是否有可能在队列上使用二维数组?窗体窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆