c# – 检查数组是空还是空?

在这代码中有一些问题:
if(String.IsNullOrEmpty(m_nameList[index]))

我做错了什么?

编辑:在VisualStudio中,m_nameList带有红色下划线,并且说“在当前上下文中不存在名称”m_nameList“?

编辑2:我添加了一些更多的代码

class SeatManager
{
    // Fields
    private readonly int m_totNumOfSeats;

    // Constructor
    public SeatManager(int maxnumOfSeats)
    {
        m_totNumOfSeats = maxnumOfSeats;

        // Create arrays for name and price
        string[] m_nameList = new string[m_totNumOfSeats];
        double[] m_priceList = new double[m_totNumOfSeats];
    }

    public int GetNumReserved()
    {
        int totalAmountReserved = 0;

        for (int index = 0; index <= m_totNumOfSeats; index++)
        {
            if (String.IsNullOrEmpty(m_nameList[index]))
            {
                totalAmountReserved++;
            }
        }
        return totalAmountReserved;
    }
  }
}

解决方法

之后编辑2:

您将m_nameList定义为构造函数的局部变量.
您的其余代码需要它作为一个字段:

class SeatManager
{       
   // Fields
   private readonly int m_totNumOfSeats;
   private string[] m_nameList;
   private double[] m_priceList;

  // Constructor
  public SeatManager(int maxnumOfSeats)
  {
     m_totNumOfSeats = maxnumOfSeats;

     // Create arrays for name and price
     m_nameList = new string[m_totNumOfSeats];
     m_priceList = new double[m_totNumOfSeats];
  }

  ....
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...