现在有一个名为classes的ArrayList中有n个String[]数组。现在要访问classes[i](实际是一个String[]数组)中的第0个String元素。我尝试用classes[i][0],提示无法在object类型上应用[];我换用((String[])(classes[i]))[0],能通过编译,但是在运行的时候提示无法将类型为“System.Collections.ArrayList”的对象强制转换为类型“System.String[]”。求解,如何访问这个String元素?3Q

解决方案 »

  1.   

    先转换为object类型,然后再转换成string数组类型,没有具体测试,看看行不行~~
      

  2.   

    MessageBox.Show(((String[])classes[0])[1]);
    在2008中可以运行,估计你ARRAYLIST中放的东西类型不一致
      

  3.   


    都是String。没有其他类型。
      

  4.   

    先声明一个object变量,在遍历中将classes[i][0]赋给object变量
      

  5.   

    IList strList = classes[i] as IList;if(strList == null)
    {
         throw new Exception("这个元素为空,或者不是一个数组或者列表");
    }string theString = strList[j] as string;
      

  6.   

    你的程序中Add string[] 的地方应该有问题(猜的)
    看看这个吧:ArrayList arr=new ArrayList();
    string []str1=new string[]{"1","2","3"}
    string []str2=new string[]{"4","5","6"}
    arr.Add(str1);
    arr.Add(str2);
    Response.Write(((string[])arr[0])[0]);
    //输出1