6
Reply

Need help with "IndexOutOfRangeException was unhandled"

Nova

Nova

Oct 25 2012 7:33 AM
3.4k

Hi,

I´m in a course for C# beginners. I´ve run into a little problem. I use this code for count "vacant" seats, "reserved seats" and "all seats" depending of which one´s selected in my Combobox. For example, if I select "vacant" should just all Vacant seats, with seatnumbers, names and prices be shown in the ListBox. Here´s my code:

public string[] GetSeatInfoAt(DisplayOptions choice)
        {
            string[] arrayList = new string[0]; //just creates an empty array
            string status = null;
            int n_vacant = 0;  
            int n_reserved = 0;
            for (int i = 0; i < m_totNumOfSeats; i++ )
            {
                switch (choice)
                {
                    case DisplayOptions.VacantSeats:
                        if (string.IsNullOrEmpty(m_nameList[i]))
                        {
                            status = "Vacant";
                            Array.Resize(ref arrayList, n_vacant);
                            arrayList[n_vacant] = string.Format("{0,3} {1,-8} {2,-25}{3,8:f2}", Convert.ToString(i + 1), status, m_nameList[i], m_priceList[i]);
                            n_vacant = n_vacant + 1; //För att räkna upp antal "Vacant"
                        }
                        break;

Answers (6)