Check if array is null or empty?

c#

Solution

After Edit2:

You are defining `m_nameList` as a local variable of the constructor. The rest of your code needs it as a field:

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

  ....
}

Problem

I have some problem with this line of code: ``` if(String.IsNullOrEmpty(m_nameList[index])) ``` What have I done wrong? EDIT: The m_nameList is underlined with red color in VisualStudio, and it says "the name 'm_nameList' does not exist in the current context"?? EDIT 2: I added some more code ``` 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; } } } ```

Original source