'C# - Creating multiple lists based on int in Console
I want to create multiple lists from a given size. Imagining it could look something like this :
int Size = int.Parse(Console.ReadLine());
for (int i = 0; i < Size; i++)
{
List<string> ListName + i = new List<string>();
}
So for example if size = 5 I'd get 5 lists :
ListName0
ListName1
ListName2
ListName3
ListName4
Solution 1:[1]
the common way is to use a dictionary
var list = new Dictionary<string, List<string>>();
int size = int.Parse(Console.ReadLine());
for (int i = 0; i < size; i++)
list["Name"+i.ToString()] = new List<string>();
how to use
list["Name1"].Add( "hello world");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
