Declaring an array of linked list in C#
arrays, c#, linked-list
Solution
You declare an array with just [].
LinkedList[] XMLList;
Then you instantiate it with the size.
XMLList = new LinkedList[2];
Or both at the same time:
LinkedList[] XMLList = new LinkedList[2];
To add LinkedLists to this array you type:
XMLList[0] = new LinkedList();
XMLList[1] = new LinkedList();
Problem
I got the compile error message "Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)" when I tried to declare an array of linked lists. ``` public LinkedList<LevelNode>[2] ExistingXMLList; ``` Also, if I wanted to create a small array of strings, isn't the following the correct way? ``` string [2] inputdata; ```