现在有一个名为classes的ArrayList中有n个String[]数组。现在要访问classes[i](实际是一个String[]数组)中的第0个String元素。我尝试用classes[i][0],提示无法在object类型上应用[];我换用((String[])(classes[i]))[0],能通过编译,但是在运行的时候提示无法将类型为“System.Collections.ArrayList”的对象强制转换为类型“System.String[]”。求解,如何访问这个String元素?3Q
在2008中可以运行,估计你ARRAYLIST中放的东西类型不一致
都是String。没有其他类型。
{
throw new Exception("这个元素为空,或者不是一个数组或者列表");
}string theString = strList[j] as 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