1

I am trying to nest a list of objects in a list; I have tried the following:

Instantiation:

  public static List<PhonePeople> Helpdesk, Admins = new List<PhonePeople>();
  public static List<List<PhonePeople>> PDepartments = 
          new List<List<PhonePeople>>{Helpdesk,Admins};

Attempting to add to the helpdesk list as follows:

 MainWindow.PDepartments[counter].Add(thisPerson);

Error:

"Object reference not set to an instance of an object"

I defined counter to 0 , 0 is the index for helpdesk. Mainwindow is where the static list resides. I believe there is an issue with my List of list's or the way i am adding to it;

whats wrong?

Alexei Levenkov
  • 96,782
  • 12
  • 124
  • 169
ModS
  • 776
  • 2
  • 10
  • 27
  • 2
    Note that I think it is not direct duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) as it more about declaring multiple variables in single statement. @Mods, consider reading the linked question to help you with debugging this type f exception (now and later). – Alexei Levenkov Sep 26 '14 at 15:16
  • Thanks Alexei; Will do this next time, I skimmed the titles but was close minded on "nested lists" instead of all the information involved. – ModS Sep 26 '14 at 16:20

1 Answers1

6

Your line public static List<PhonePeople> Helpdesk, Admins = new List<PhonePeople>(); is only instantiating Admins not HelpDesk

Jeffrey Wieder
  • 2,288
  • 1
  • 12
  • 12