日期:2014-05-18  浏览次数:21111 次

arraylist数组参数设置问题,求解,急……
问题:
把二维数组每一列编号存储在arrayLianHao中,当每一列元素“1”的个数少于2时,删除此列,并删除arrayLianHao中对应编号。然后二维数组每一列两两作“与”运算,arrayLianHao中对应元素连接,如:二维数组第一列与第二列作“与”运算,则arrayLianHao中第一列和第二列编号连接,成为“01”,依次类推,形成新数组。
代码错误(红色部分):
未处理 ArgumentOutOfRangeException
索引超出范围。必须为非负值并小于集合大小。参数名:index



  class Program
  {
  static void Main(string[] args)
  {
  ArrayList arrayLianHao = new ArrayList();
  string []number1 = { "0", "1", "2", "3", "4", "5" };
  arrayLianHao.AddRange(number1);
  int[,] arrayYuanShi = {{0,0,0,0,0,0},{0,1,0,1,0,0},{1,0,1,0,1,0},{1,1,1,0,1,0},{0,0,1,0,1,0}};
  bool Flag; int k; k = arrayYuanShi.GetLength(1); ArrayList arrayLianHao1 = new ArrayList();
  do
  {
  int countPD = 0;  
  int[]arrayPD = PanDuan(arrayYuanShi,k,arrayLianHao);
  for(int i = 0;i<arrayPD.Length;i++){countPD ++;}
  if (countPD == 0) { break;}
   
  Console.WriteLine(arrayYuanShi.GetLength(1));
  Console.ReadLine();  
  int[,]arrayXJZ = XinJuZhen(arrayYuanShi,arrayPD , k);
   
  for(int m = 0;m< arrayXJZ.GetLength(0);m++)
  {
  for(int n = 0;n<arrayXJZ.GetLength(1);n++)
  {Console.Write(arrayXJZ[m,n]);}
  Console.WriteLine();
  }
  Console.ReadLine();
  k = arrayYuanShi.GetLength(1) - countPD;  
  int [,] arrayYCZ = YuCaoZuo( arrayXJZ,countPD,k,arrayLianHao,arrayLianHao1);
  for(int b = 0;b<5;b++)
  {
  for(int c = 0;c<k*(k-1)/2;c++ )
  {Console.Write(arrayYCZ[b,c]);}
  Console.WriteLine();
  }  
  Console.ReadLine();

  for (int i = 0; i < 5; i++)
  for (int j = 0; j < 6; j++)
  {
  arrayYuanShi[i, j] = 0;
  arrayYuanShi[i, j] = arrayYCZ[i, j];
  }
  arrayLianHao.Clear();
for (int x= 0; x < k * (k - 1) / 2; x++)
arrayLianHao.Add(arrayLianHao1[x]);[b][/b] k = k * (k - 1) / 2;
  if (countPD == 0) Flag = false;
  else Flag = true;  
  }while(Flag);

  for (int i = 0; i < arrayLianHao.Count; i++)
  { Console.WriteLine(arrayLianHao[i]); }
  Console.ReadLine();
  Console.WriteLine("ok!");
  Console.ReadLine();
  }  
   
  public static int[] PanDuan(int[,] arrayYuanShi,int k,ArrayList arrayLianHao) 
  {
  int count = 0;
  for(int j = 0;j < k;j++)
  {
  count = 0;
  for(int i = 1;i<arrayYuanS