ankit r

ankit r

  • NA
  • 3
  • 2.1k

Object reference not set to an instance of an object.

Apr 13 2012 12:55 PM
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)