Declaring an array of linked lists in C #

I got a compilation error message: "The size of the array cannot be specified in the variable declaration (try initializing with the" 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, does this not match the correct path?

string [2] inputdata;
+3
source share
3 answers

You declare an array only with [].

LinkedList[] XMLList;

Then you create an instance with a size.

XMLList = new LinkedList[2];

Or both at the same time:

LinkedList[] XMLList = new LinkedList[2];

To add LinkedLists to this array, enter:

XMLList[0] = new LinkedList();
XMLList[1] = new LinkedList();
+7
source

try the following:

LinkedList[] ExistingXMLList = new LinkedList[2];
+1
source

 LinkedList < > [] List = LinkedList < > [2];
1

-1

Source: https://habr.com/ru/post/1742556/


All Articles