Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An array of List in c#

Tags:

arrays

c#

list

I want to have an array of Lists. In c++ I do like:

List<int> a[100]; 

which is an array of 100 Lists. each list can contain many elements. I don't know how to do this in c#. Can anyone help me?

like image 664
orezvani Avatar asked Sep 18 '11 21:09

orezvani


People also ask

Is there an array list in C?

There's no such thing in the standard C library. People usually roll their own. While the terms vector and ArrayList usually refer to the same datastructure (resizable array), a linked list is something completely different. So do you want a resizable array or a linked list?

What is array of linked list?

An array of linked lists is an important data structure that can be used in many applications. Conceptually, an array of linked lists looks as follows. An array of linked list is an interesting structure as it combines a static structure (an array) and a dynamic structure (linked lists) to form a useful data structure.

What is an array in C with example?

An array is a variable that can store multiple values. For example, if you want to store 100 integers, you can create an array for it. int data[100];

How do you declare an array in C?

To create an array, define the data type (like int ) and specify the name of the array followed by square brackets []. To insert values to it, use a comma-separated list, inside curly braces: int myNumbers[] = {25, 50, 75, 100}; We have now created a variable that holds an array of four integers.


1 Answers

You do like this:

List<int>[] a = new List<int>[100]; 

Now you have an array of type List<int> containing 100 null references. You have to create lists and put in the array, for example:

a[0] = new List<int>(); 
like image 157
Guffa Avatar answered Sep 27 '22 17:09

Guffa