首页 > 代码库 > 对N个数组进行操作。先把这N个一维数组合并成一个2为数组;然后进行操作
对N个数组进行操作。先把这N个一维数组合并成一个2为数组;然后进行操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
using System.Diagnostics;
namespace Hecha.Test
{
class Program
{
static void Main(string[] args)
{
List<string>[] aa = new List<string>[5];
List<string> a = new List<string> { "张", "李"};
List<string> b = new List<string> { "三", "四"};
List<string> c = new List<string> { "在", "不在" };
List<string> d = new List<string> { "家", "公司" };
List<string> e = new List<string> { "打游戏", "吃饭" };
aa[0] = a;
aa[1] = b;
aa[2] = c;
aa[3] = d;
aa[4] = e;
ArrGroup ff = new ArrGroup(aa);
ff.mySelf();
ArrayList dataSource = ff._firstList;
for (int i = 0; i < dataSource.Count; i++)
Console.Write(dataSource[i].ToString()+"\r\n");
Console.Read();
}
class ArrGroup
{
List<string>[] intList;
ArrayList firstList = new ArrayList();
public ArrayList _firstList
{
get
{
return this.firstList;
}
}
public ArrGroup(List<string>[] intList)
{
this.intList = intList;
firstList.AddRange(intList[0]);
}
public void mySelf()
{
for (int i = 1; i < intList.Length; i++)
Display(intList[i]);
}
string strCount;
private void Display(List<string> list)
{
strCount = string.Empty;
for (int i = 0; i < firstList.Count; i++)
{
for (int j = 0; j < list.Count; j++)
{
strCount += firstList[i].ToString() + list[j].ToString() + "&";
}
}
firstList.Clear();
firstList.AddRange(strCount.Split(‘&‘));
firstList.RemoveAt(firstList.Count - 1);
}
}
}
}