3
Reply

Object reference not set to an instance of an object.

ankit r

ankit r

Apr 13 2012 12:55 PM
1.8k
Hello everyone and thanks in advance.
I am getting an error " Object reference not set to an instance of an object." when I try to add an item to a integer list of class "FreeHoursClass" which has a public list "FreeHoursList".

This is my code.


public class FreeHoursClass
    {

       public  List<int> FreeHoursList = new List<int>();
    }


private void button1_Click(object sender, EventArgs e)
        {
            FreeHoursClass[] ff = new FreeHoursClass[30];
            ff[5].FreeHoursList.Add(9);
            MessageBox.Show(ff[5].FreeHoursList[0].ToString());
        }

Answers (3)