3
Answers

Object reference not set to an instance of an object.

ankit r

ankit r

12y
1.8k
1
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)