有多个数组.如何组成一个二维数组
如:
数组一:红色,蓝色,白色
数组二:大,中,小
最终组成的数组为:{红色,大}{红色,中}{红色,小}{蓝色,大}{蓝色,中}{蓝色,小}{白色,大}{白色,中}{白色,小}
条件:一维数组的个数不确定,有可能有三个,有可能有四个等.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//初始化
string[] arr1 = new string[] { "红色", "蓝色", "白色" };
string[] arr2 = new string[] { "大", "中", "小" };
Dictionary <string, List <string>> a = new Dictionary <string, List <string>>();
foreach (string i in arr1)
{
List <string> b = new List <string>();
a.Add(i, b);
foreach (string j in arr2)
{
a[i].Add(j);
}
}
//分配
string[] arr3 = new string[arr1.Length*arr2.Length];
int k=0;
foreach(string i in a.Keys)
{
foreach(string j in a[i])
{
arr3[k] = i + "," + j;
k++;
}
}
///输出显示
foreach(string m in arr3)
{
Console.WriteLine(m);
}
}
}
}