首先,我会问用户“你要输入多少个名字?”。 一旦他们进入,我想创建那么多的数组。 如何在c#中动态创建n个数组?
Console.WriteLine("How many names you want to Enter?");
int nameCount = Convert.ToInt32(console.Readline());
//I know following code is not possible.But How to make it possible?
for(int i=1;i<=nameCount;i++)
{
string[] name+i = new string[45];
//what I mean is string[] name1 = new string[45];
string[] name+i = new string[45];
string[] name+i = new string[45];
string[] name+i = new string[45];
.
.
.
}
答案 0 :(得分:5)
尝试List<string[]>
List<string[]> list=new List<string[]>();
for(int i=1;i<5;i++)
{
list.add(new string[45]);
}
或者
Dictionary<string,string[]> dictionary;
dictionary=new Dictionary<string,string[]>();
for(int i=1;i<=5;i++)
{
dictionary.add("string" + i,new string[45]);
}